[英]How can I use WP_Query to display selected Category posts from the custom post?
I am using custom post type plugin and I am trying to loop only selected post for a particular category within my custom post. 我正在使用自定义帖子类型插件,我试图在我的自定义帖子中仅循环选定的帖子。 I would like to loop only selected category.
我想循环选择的类别。 Any suggestion?
有什么建议吗?
Here is my code : 这是我的代码:
<?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(),'');
?>
According to the wp_query docs 根据wp_query文档
$loop=new WP_Query(array(
'post_type' => 'custom post',
'taxonomy' =>'private',
'sort_column' => 'post_date',
'posts_per_page'=> -1,
'order' => 'ASC',
'cat' => 19
)
);
Use tax query of wordpress inside the wp_query 在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 );
and replace the 'terms' => 'bob',
with 'terms' => '<your category slug>',
Slug can be checked from back-end 并用
'terms' => '<your category slug>',
替换'terms' => 'bob',
可以从后端检查Slug
use it like this: 像这样用它:
<?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(),'');
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.