admin 管理员组文章数量: 1184232
I have a Taxonomy, “Genre”. “Genre” has a Term, “advert”. I want my taxomomy template to grab all Custom Posts attached to that term, sort them by my last_name, first_name, short_title Custom Fields, and output.
But my custom query is returning 0 posts! I would love to get another set of eyes on this. I’m missing something!
<?php
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'genre',
'terms' => array( 'advert' )
)
),
'meta_query' => array(
'relation' => 'AND',
'last_name_clause' => array(
'key' => 'last_name',
'compare' => 'EXISTS',
),
'first_name_clause' => array(
'key' => 'first_name',
'compare' => 'EXISTS',
),
'short_title_clause' => array(
'key' => 'short_title',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'last_name_clause' => 'ASC',
'first_name_clause' => 'ASC',
'short_title_clause' => 'ASC',
),
);
$newQuery = new WP_Query( $args );
?>
Best regards,
Mark
I have a Taxonomy, “Genre”. “Genre” has a Term, “advert”. I want my taxomomy template to grab all Custom Posts attached to that term, sort them by my last_name, first_name, short_title Custom Fields, and output.
But my custom query is returning 0 posts! I would love to get another set of eyes on this. I’m missing something!
<?php
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'genre',
'terms' => array( 'advert' )
)
),
'meta_query' => array(
'relation' => 'AND',
'last_name_clause' => array(
'key' => 'last_name',
'compare' => 'EXISTS',
),
'first_name_clause' => array(
'key' => 'first_name',
'compare' => 'EXISTS',
),
'short_title_clause' => array(
'key' => 'short_title',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'last_name_clause' => 'ASC',
'first_name_clause' => 'ASC',
'short_title_clause' => 'ASC',
),
);
$newQuery = new WP_Query( $args );
?>
Best regards,
Mark
Share Improve this question asked Apr 26, 2022 at 20:24 Mark CyzykMark Cyzyk 11 Answer
Reset to default 0You're looking for custom posts, but don't define post_type in your query, which means it will default to the core post post type only.
You need to incorporate
'post_type' => 'my-cpt'
into your query.
本文标签: sortWPQuery Taxonomy list of attached items to a Term sorted
版权声明:本文标题:sort - WP_Query, Taxonomy, list of attached items to a Term, sorted 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1738609606a1992591.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论