gpt4 book ai didi

wordpress - WP_Query 多个帖子类型和分类法

转载 作者:行者123 更新时间:2023-12-03 20:22:36 25 4
gpt4 key购买 nike

我想从两种帖子类型中获得结果,

1)发布,只显示“业务”踢球者
2)本地新闻,显示所有踢球者

我到目前为止:

$args=array(
'cat' => $my_category_id,
'post_status' => 'publish',
'posts_per_page' => 5,
'post_type' => array('post', 'local-news'),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'postkicker',
'term' => 'business'
),
array(
'taxonomy' => 'impactkicker',
),
),
'orderby' => 'date',
'order' => 'DESC'
);

目前没有显示两种帖子类型,有什么建议吗?提前致谢

最佳答案

你需要确保你已经连接了你的cpt local-newscategory分类法也是如此,因为您正在尝试按此分类法进行选择。这是广泛评论的方法,我猜它可以满足您的需求。至少如果我清楚地了解你的想法。您可以更改 tax_query主要关系 OR而不是 AND如果它们也没有设置类别,则输出项目。

$args = array(
// 'cat' => $my_category_id, // better replace it with category in tax_query, see below.
'post_status' => 'publish',
'posts_per_page' => 5,
'post_type' => array( 'post', 'local-news' ),
'tax_query' => array(
'relation' => 'AND', // we set it to AND because we want all posts of this category i guess.
array(
'taxonomy' => 'category',
'term' => $my_category_id,
'field' => 'term_id',
'operator' => 'IN', // just to be more explicit.
),
array( // we create nested sub queries which will filter by other 2 taxonomies, which in turn has OR relation.
'relation' => 'OR',
array(
'taxonomy' => 'postkicker',
'field' => 'slug', // by default it's term_id and you are passing in a slug so set it explicitly.
'term' => 'business',
'operator' => 'IN', // just to be more explicit.
),
array(
'taxonomy' => 'impactkicker',
'field' => 'slug', // set these or not add rule for taxonomy at all.
'term' => 'your-term-slug', // same here.
'operator' => 'IN', // it's a default value, but ou can set 'EXISTS' if you need to check if whatever term of such taxonomy is assigned.
),
),
),
'orderby' => 'date',
'order' => 'DESC',
);

关于wordpress - WP_Query 多个帖子类型和分类法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39780107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com