在POST类型中注册非层次分类和show meta框

时间:2018-12-04 作者:joshmoto

我试图在我的产品帖子类型中显示一个元框,但我收到了这个警告错误。。。

enter image description here

警告错误。。。

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

请参阅下面的注册分类代码。。。

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();
在仪表板侧栏中,它工作正常,只是product post metabox出现了此错误。

以前有人有过这个问题吗?

ThanksJosh谢谢

1 个回复
最合适的回答,由SO网友:JHoffmann 整理而成

这个meta_box_cb 参数应为回调函数。所以应该是callable.

正如米洛在评论中所建议的那样,尽量不使用该参数,然后将使用metabox内容的默认函数。如果您确实想要自定义metabox输出,则只需添加自己的metabox函数。

    $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\' ),
    );
如中所述Code Reference, post_tags_meta_box 是非层次分类法的默认值。如果不使用参数,则使用默认值。由于明确提到它是可选的,所以完全可以不使用它。

相关推荐

自定义模板earch.php中的搜索结果

现在我在搜索结果页面(search.php)中遇到了一个问题,结果是由索引页面模板显示的,而不是它的模板,它显示所有帖子,不管搜索者是否输入了内容我的索引。php页面<?php get_header(); ?> <?php $search = $_get[\'search\']; $args = array( \'post_title_like\' => $search ); $res = new wp_query($args