我正在使用自定义帖子类型插件,我试图在我的自定义帖子中仅循环选定的帖子。我想循环选择的类别。有什么建议吗?
这是我的代码:
<?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(),'');
?>
答案 0 :(得分:0)
$loop=new WP_Query(array(
'post_type' => 'custom post',
'taxonomy' =>'private',
'sort_column' => 'post_date',
'posts_per_page'=> -1,
'order' => 'ASC',
'cat' => 19
)
);
答案 1 :(得分:0)
在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可以从后端检查
答案 2 :(得分:0)
像这样使用它:
<?php
$loop=new WP_Query(array(
'post_type'=>'custom post';
'posts_per_page'=> -1 ,
'order' => 'ASC',
'orderby' => 'ID',
'tax_query' => array(
array(
'taxonomy' => 'private',
'field' => 'slug',
'terms' => 'bob'
),
),
);
);
if ( $loop->have_posts() ){?>
<?php
while ( $loop->have_posts() )
{
$loop->the_post();
$meta=get_post_meta(get_the_id(),'');
?>