admin管理员组文章数量:1291044
I create a custom taxonomy called "site". I cannot figure out what code to put in single.PHP to show related posts ONLY from "site" custom taxonomy.
Please help.
I create a custom taxonomy called "site". I cannot figure out what code to put in single.PHP to show related posts ONLY from "site" custom taxonomy.
Please help.
Share Improve this question asked Jun 12, 2021 at 9:12 Alex897Alex897 1 1- Does this answer your question? Show related posts on single page by custom taxonomy on custom post – bosco Commented Jun 12, 2021 at 15:43
1 Answer
Reset to default 0What you need is to add a tax_query
to your WP_Query
arguments, where you check that your taxonomy exists on the posts you are querying.
Here is an example that fetches the 3 latest published posts that have the taxonomy site set.
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 3,
'tax_query' => array(
array(
'taxonomy' => 'site',
'operator' => 'EXISTS',
),
),
);
$the_query = new WP_Query( $args );
Good reads
- Documentation for WP_Meta_Query
- Documentation for WP_Query
本文标签: Show recent posts from a custom taxonomy in wordpress
版权声明:本文标题:Show recent posts from a custom taxonomy in wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741507832a2382427.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论