I am trying to show a meta box in my product post type, but I'm getting this warning error...

enter image description here

Warning error...

Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in /home/.../wp/wp-admin/includes/template.php on line 1073

See my register taxonomy code below...

class Types {


    /**
     * Method to run on WordPress initialisation
     *
     * @uses init action
     * @see  https://codex.wordpress.org/Plugin_API/Action_Reference/init
     */
    public function action_init () {

        $this->register_taxonomies();

    }


    /**
     * Registers Taxonomies
     * 
     * @see https://codex.wordpress.org/Function_Reference/register_taxonomy
     * @return void
     */
    protected function register_taxonomies () {

        // product tag taxonomy
        $labels = array(
            'name'                  => _x( 'Tags', 'taxonomy general name' ),
            'singular_name'         => _x( 'Tag', 'taxonomy singular name' ),
            'search_items'          => __( 'Search tags' ),
            'popular_items'         => __( 'Popular tags' ),
            'all_items'             => __( 'All tags' ),
            'parent_item'           => null,
            'parent_item_colon'     => null,
            'edit_item'             => __( 'Edit category' ),
            'update_item'           => __( 'Update category' ),
            'add_new_item'          => __( 'Add new category' ),
            'new_item_name'         => __( 'New category name' ),
            'separate_items_with_commas'  => __( 'Separate tags with commas' ),
            'add_or_remove_items'   => __( 'Add or remove tags' ),
            'choose_from_most_used' => __( 'Choose from the most used tags' ),
            'not_found'             => __( 'No tags found.' ),
            'menu_name'             => __( 'Tags' ),
        );

        $args = array(
            'hierarchical'          => false,
            'labels'                => $labels,
            'show_ui'               => true,
            'show_admin_column'     => true,
            'update_count_callback' => '_update_post_term_count',
            'query_var'             => true,
            'rewrite'               => array( 'slug' => 'tags' ),
            'meta_box_cb'           => true
        );

        register_taxonomy('product_tags', array('product'), $args );

    }


} new Types();

In the dashboard sidebar it works fine, it's just the product post metabox is getting this error.

Has anyone had this problem before?

Thanks Josh

  • I don't think true is a valid value for meta_box_cb, try removing that argument to see if that works. – Milo Dec 4 at 16:03
  • Thanks Milo, I re-read the documentation properly this time and should be 'meta_box_cb' => 'post_tags_meta_box' – joshmoto Dec 4 at 22:29
up vote 1 down vote accepted

The meta_box_cb argument is expected to be a callback function. So it should be a callable.

As Milo suggested in his comment, try to leave that argument away, then the default function for the metabox content will be used. You only need to add an own metabox function if you actually want to customize the metabox output.

    $args = array(
        'hierarchical'          => false,
        'labels'                => $labels,
        'show_ui'               => true,
        'show_admin_column'     => true,
        'update_count_callback' => '_update_post_term_count',
        'query_var'             => true,
        'rewrite'               => array( 'slug' => 'tags' ),
    );

As described in the Code Reference, post_tags_meta_box is the default value for non-hierarchical taxonomies. The default value is used, if the argument is left away. As it is explicitely mentioned as being optional, it is perfectly ok to just leave it away.

  • I thought i replied to Milo's answer earlier, what he said he put me on the right track. I didn't read the documentation properly. Yes it has to be a callable object you're right. Leaving that argument blank did not add the meta box to my product post type. This is what I used in the end... 'meta_box_cb' => 'post_tags_meta_box'. – joshmoto Dec 4 at 22:31
  • @joshmoto That is exactly the default value in case the argument is omitted. I added this to my answer with a relevant link. – JHoffmann Dec 4 at 22:43
  • Its so bizarre, with out it does not show in my custom post-type. Would I need to add it to my post type supports? – joshmoto Dec 4 at 22:45
  • I don't think that it is needed. And from inspecting the source code in class-wp-taxonomy.php and edit-form-advanced.php I don't see any reason why it should not appear, unless something uses a filter like register_taxonomy_args to set it to false. But good that you got it working. – JHoffmann Dec 4 at 23:06
  • Yeah it's working fine now. However, I've got 4 extra registered taxonomies i.imgur.com/5Yhob5W.png in my post type and none of them are showing. Apart from my tags taxonomy which is explicitly using the meta_box_cb callback. I have only got one plugin installed, Advanced Custom Fields. I searched my theme for register_taxonomy_args and nothing to show. In ACF i've definitely not turned off any meta boxes yet, and they are not appearing in the dashboard screen options. Very strange. – joshmoto Dec 4 at 23:16

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.