【发布时间】:2019-09-24 09:20:02
【问题描述】:
我有一个名为 resources 的自定义帖子类型:
register_post_type(
'resources',
tp_build_post_args(
'resources', 'Resource', 'Resources',
array(
'menu_icon' => 'dashicons-welcome-write-blog',
'menu_position' => 20,
'public' => true,
'supports' => array('editor', 'title','author','thumbnail', 'revisions'),
'taxonomies' => array('sector', 'subject', 'type'),
)
)
);
还有一个名为type的分类法:
register_taxonomy(
'type',
'type',
array(
'hierarchical' => true,
'label' => 'Type',
'query_var' => true,
'rewrite' => array(
'slug' => 'type',
'with_front' => false
)
)
);
类型可以是以下之一:
- 博客
- 新闻
- 网络研讨会
我正在尝试使用wp_query 显示resources 下的所有帖子以及type“新闻”。但是,它会返回所有帖子。
我的方法在哪里分崩离析:
$card_count = 4;
$resource_type = 'News';
$args = array(
'post_type' => 'resources',
'post_status' => 'publish',
'posts_per_page' => $card_count,
//'cat' => $resource_type,
'tax_query' => array(
array(
'taxonomy' => 'type',
'terms' => $resource_type,
)
)
);
【问题讨论】:
标签: php wordpress custom-post-type