带类别的自定义帖子类型

时间:2014-01-26 作者:Manan

我已经从WordPress复制了自定义的帖子类型代码,并对其进行了修改和添加。php但类别框在哪里。我哪儿都看不见。我也想要这个职位。

I want to see this in my post

我不适合WordPress,所以请指导我解决这个问题。

谢谢:)

My Code:

function codex_custom_init() {
  $labels = array(
    \'name\'               => \'Prices\',
    \'singular_name\'      => \'Price\',
    \'add_new\'            => \'Add New\',
    \'add_new_item\'       => \'Add New Price\',
    \'edit_item\'          => \'Edit Price\',
    \'new_item\'           => \'New Price\',
    \'all_items\'          => \'All Prices\',
    \'view_item\'          => \'View Price\',
    \'search_items\'       => \'Search Prices\',
    \'not_found\'          => \'No prices found\',
    \'not_found_in_trash\' => \'No prices found in Trash\',
    \'parent_item_colon\'  => \'\',
    \'menu_name\'          => \'Prices\'
  );

  $args = array(
    \'labels\'             => $labels,
    \'public\'             => true,
    \'publicly_queryable\' => true,
    \'show_ui\'            => true,
    \'show_in_menu\'       => true,
    \'query_var\'          => true,
    \'rewrite\'            => array( \'slug\' => \'price\' ),
    \'capability_type\'    => \'post\',
    \'has_archive\'        => true,
    \'hierarchical\'       => false,
    \'menu_position\'      => null,
    \'supports\'           => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
  );

  register_post_type( \'price\', $args );
}
add_action( \'init\', \'codex_custom_init\' );

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

嘿Manan试试这个代码:

function codex_custom_init() {
  $labels = array(
    \'name\'               => \'Prices\',
    \'singular_name\'      => \'Price\',
    \'add_new\'            => \'Add New\',
    \'add_new_item\'       => \'Add New Price\',
    \'edit_item\'          => \'Edit Price\',
    \'new_item\'           => \'New Price\',
    \'all_items\'          => \'All Prices\',
    \'view_item\'          => \'View Price\',
    \'search_items\'       => \'Search Prices\',
    \'not_found\'          => \'No prices found\',
    \'not_found_in_trash\' => \'No prices found in Trash\',
    \'parent_item_colon\'  => \'\',
    \'menu_name\'          => \'Prices\'
  );

  $args = array(
    \'labels\'             => $labels,
    \'public\'             => true,
    \'publicly_queryable\' => true,
    \'show_ui\'            => true,
    \'show_in_menu\'       => true,
    \'query_var\'          => true,
    \'rewrite\'            => array( \'slug\' => \'price\' ),
    \'capability_type\'    => \'post\',
    \'has_archive\'        => true,
    \'hierarchical\'       => false,
    \'menu_position\'      => null,
    \'supports\'           => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' ),
    \'taxonomies\' => array(\'category\', \'post_tag\') // this is IMPORTANT
  );

  register_post_type( \'price\', $args );
  register_taxonomy_for_object_type(\'category\', \'price\');
}
add_action( \'init\', \'codex_custom_init\' );

结束

相关推荐

具有自定义分类的自定义帖子类型中的WP_DROPDOWN_CATEGORIES

我有一个自定义的帖子类型,它有自己的分类法,基本上“show Vinces”是帖子类型,Vincement regions是分类法。看到一个场馆无法在多个地区存在,我删除了默认的metta框,并使用wp_dropdown_categories(). 分类法项目正在输出并按我所希望的方式显示,但它们不会被提交,并且下拉列表在提交后不会保留所选内容。我已经尽我所能地查看原始metabox的各种属性,并尝试将这些属性应用到下拉列表中,但到目前为止,我没有任何乐趣。我看过一些various WPSE上的帖子和ha