WordPress自定义文章类型使用标签

WordPress自定义文章类型可以使用系统已有的分类和标签,只需要在注册自定义类型文章时,传递对应的参数即可。

register_post_type( 'ggdoc_product',
	array(
		'labels'      => array(
			'name'          => '产品',
			'singular_name' => '产品',
			'add_new'       => '添加产品',
			'add_new_item'  => '添加新产品',
		),
		'taxonomies'  => array( 'post_tag', 'post_format' ),
		'public'      => true,
		'has_archive' => true,
		'rewrite'     => array( 'slug' => 'products' ),
		'supports'    => array( 'title', 'editor', 'author', 'excerpt', 'thumbnail', 'custom-fields' )
	)
);

主要是以下代码

'taxonomies'  => array( 'post_tag', 'post_format' ),

查看还可以传递哪些参数值的代码如下:

global $wp_taxonomies;
var_dump( array_keys( $wp_taxonomies ) );
array(8) {
  [0]=>
  string(8) "category"
  [1]=>
  string(8) "post_tag"
  [2]=>
  string(8) "nav_menu"
  [3]=>
  string(13) "link_category"
  [4]=>
  string(11) "post_format"
  [5]=>
  string(8) "wp_theme"
  [6]=>
  string(21) "wp_template_part_area"
  [7]=>
  string(12) "product_type"
}

category对应于分类,post_tag对应于标签。