我已经在wordpress中创建了自定义帖子和自定义分类法

时间:2019-05-07 06:52:55

标签: wordpress

我在自定义帖子中创建了自定义帖子和自定义分类法,无法将类别分配给自定义帖子

register_post_type('gobohouse',$args);
'taxonomies'=> array('hosuehold','post_tag');
register_taxonomy('hosuehold',array('gobohouse'),$args);
register_post_type('gobohouse',$args);
'taxonomies'=> array('hosuehold','post_tag');
register_taxonomy('hosuehold',array('gobohouse'),$args);

我想分配自定义分类法,但无法这样做

1 个答案:

答案 0 :(得分:1)

嗨,请检查以下代码作为参考:

function gobohouse_post_type() {
  register_post_type( 'gobohouse',
    array(
      'labels' => array(
        'name' => __( 'Gobohouse' ),
        'singular_name' => __( 'Gobohouse' ),
        'menu_name' => __( 'Gobohouse', 'theme' ),
        'name_admin_bar' => __( 'Gobohouse', 'theme' ),
      ),
      'label' => __( 'Gobohouse', 'theme' ),
      'public' => true,
      'taxonomies' => array( 'hosuehold'),
      'has_archive' => false,
      'supports' => array( 'title','editor','thumbnail' )
    )
  );
}
add_action( 'init', 'gobohouse_post_type' );

add_action( 'init', 'create_hosuehold_tax' );

function create_hosuehold_tax() {
  register_taxonomy(
    'hosuehold',
    'gobohouse',
    array(
      'label' => __( 'Hosuehold' ),
      'rewrite' => array( 'slug' => 'hosuehold' ),
      'hierarchical' => true,
      'publicly_queryable' => false,
      'show_admin_column' => true
    )
  );
}