【问题标题】:Wordpress custom taxonomy move meta_boxWordpress 自定义分类移动 meta_box
【发布时间】:2013-01-24 22:43:30
【问题描述】:

我有一个自定义元框(分类),位于我的自定义帖子的一侧。我想将它移动到正常位置,但是当我删除它(remove_meta_box)和重新添加(add_meta_box)时,我只得到 bar,没有选择任何东西的选项。我认为我没有编写正确的 $callback,但我尝试了很多变体,但没有任何线索。

function create_isotope_taxonomies()
{
  $labels = array(
    'name' => _x( 'Select Category', 'taxonomy general name' ),
    'singular_name' => _x( 'Category', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Categories' ),
    'popular_items' => __( 'Popular Categories' ),
    'all_items' => null,
    'parent_item' => null,
    'parent_item_colon' => null,
    'edit_item' => __( 'Edit' ),
    'update_item' => __( 'Update' ),
    'add_new_item' => __( 'Add New' ),
    'new_item_name' => __( 'New Category' ),
    'separate_items_with_commas' => __( 'Separate writers with commas' ),
    'add_or_remove_items' => __( 'Add or remove categories' ),
    'choose_from_most_used' => __( 'Choose from the most used categories' ),
    'menu_name' => __( 'Categories' ),
  );

  register_taxonomy('fzisotope_categories','fzisotope_post',array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => true,
    'update_count_callback' => '_update_post_term_count',
    'query_var' => true,
    'rewrite' => array( 'slug' => 'fzisotope_categories' ),
  ));
}



function fzisotope_categories_meta_box(){
remove_meta_box('fzisotope_categoriesdiv', 'fzisotope_post', 'side');
        add_meta_box( 'fzisotope_categoriesdiv', 'Select Category', 'fzisotope_categories_meta_box', 'fzisotope_post', 'normal', 'high');
        //print '<pre>';print_r( $wp_meta_boxes['post'] );print '<pre>';
}
add_action( 'admin_init', 'fzisotope_categories_meta_box', 0 );

感谢阅读

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    你必须使用: post_categories_meta_box 用于具有层次结构的分类法。

    remove_meta_box('fzisotope_categoriesdiv', 'fzisotope_post', 'side');
    add_meta_box( 'fzisotope_categoriesdiv', 'XXXXXXXXXXX', 'post_categories_meta_box', 'post', 'normal', 'high', array( 'taxonomy' => 'fzisotope_categories' ));
    

    【讨论】:

    • 如果您使用 自定义帖子类型 执行此操作,则需要将 post 替换为 custom_post_type_slug
    猜你喜欢
    • 1970-01-01
    • 2012-06-21
    • 1970-01-01
    • 2013-08-03
    • 2014-07-20
    • 2016-11-05
    • 2017-04-16
    • 2013-09-29
    • 1970-01-01
    相关资源
    最近更新 更多