我正在使用自定义帖子类型插件,我试图在我的自定义帖子中只循环选择特定类别的帖子。我只想循环选定的类别。有什么建议吗?
这是我的代码:
<?php
$loop=new WP_Query(array(
'post_type'=>'custom post';
'taxonomy '->'private';
'sort_column' => 'post_date',
'posts_per_page'=> -1 ,
'order' => 'ASC')
);
if ( $loop->have_posts() ){?>
<?php
while ( $loop->have_posts() )
{
$loop->the_post();
$meta=get_post_meta(get_the_id(),'');
?>
最佳答案
在wp_query中使用wordpress的税务查询
$args = array(
'post_type'=>'custom post';
'posts_per_page'=> -1 ,
'order' => 'ASC'
'orderby' => 'ID'
'tax_query' => array(
array(
'taxonomy' => 'private',
'field' => 'slug',
'terms' => 'bob',
),
),
);
$query = new WP_Query( $args );
并替换 'terms' => 'bob',
与 'terms' => '<your category slug>',
可以从后端检查 Slug
关于php - 如何使用 WP_Query 显示自定义帖子中的选定类别帖子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35407412/