Custom Admin Column: Uncaught Error: Class "MBAC\Post" not found

Support MB Admin Columns Custom Admin Column: Uncaught Error: Class "MBAC\Post" not found

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #46940
    FizzPop MediaFizzPop Media
    Participant

    I am using the documentation here to create custom code to include the slug of the post in the admin columns.
    https://docs.metabox.io/extensions/mb-admin-columns/#custom-admin-columns

    The first error I get is:
    PHP Fatal error: Uncaught Error: Class "MBAC\Post" not found

    What am I missing?

    I am running Metabox 5.10.3 and AIO 1.30.5

    <div>
    class Prefix_Custom_Admin_Columns extends \MBAC\Post {
        public function columns( $columns ) {
            $columns  = parent::columns( $columns );
            $position = 'after';
            $target   = 'title';
            $this->add( $columns, 'post_name', 'Slug', $position, $target );
            // Add more if you want
            return $columns;
        }
        public function show( $column, $post_id ) {
            switch ( $column ) {
                case 'post_name':
                    echo $post->post_name;;
                    break;
                // More columns
            }
        }
    }
    </div>
    <div>
    Here is the function:
    add_action( 'admin_init', 'prefix_add_custom_columns', 20 );
    function prefix_add_custom_columns() {
        require_once 'custom.php';
        $post_type = 'post';
        new Prefix_Custom_Admin_Columns( $post_type, [] );
    }
    </div>
    #46956
    PeterPeter
    Moderator

    Hello,

    Do you add the file custom.php and the code to a custom plugin? Maybe the plugin is executed before Meta Box plugins so the Meta Box features are not available and cause the issue. Please try to add the file and custom code to a theme or child theme folder and check the issue again.

    #46960
    FizzPop MediaFizzPop Media
    Participant

    I have resolved the previous issue.

    Now I am trying to add a custom field for any custom post type registered with metabox.

    If I hardcode the values of postTypes vendor and home in the array it works fine.
    However, I can't figure out how to query an array of all postTypes that exist. Please advise.

    `
    add_action('admin_init', 'prefix_add_custom_columns', 20);

    function prefix_add_custom_columns() {
    require_once 'custom-admin-columns.php';
    $post_types = ['vendor';'home'];
    if (!empty($post_types)) {
    foreach ($post_types as $post_type) {
    // Apply custom admin columns to each post type
    new Prefix_Custom_Admin_Columns($post_type, []);
    }
    }
    }
    `

    #46961
    FizzPop MediaFizzPop Media
    Participant
    
    add_action('admin_init', 'prefix_add_custom_columns', 20);
    
    function prefix_add_custom_columns() {
        require_once 'custom-admin-columns.php';
        $post_types = ['vendor';'home'];
        if (!empty($post_types)) {
            foreach ($post_types as $post_type) {
                // Apply custom admin columns to each post type
                new Prefix_Custom_Admin_Columns($post_type, []);
            }
        }
    }
    
    #46971
    PeterPeter
    Moderator

    Hello,

    You can use the WordPress function get_post_types() to get available post types on your site.
    https://developer.wordpress.org/reference/functions/get_post_types/

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.