[英]Display posts of specific Category
Lets say for instance I only want to display posts that are assigned to BOTH categories 2 & 5. 假设例如,我只想显示分配给类别2和5的帖子。
I don't want to see posts that are only assigned to 2 OR 5. 我不想看到仅分配给2或5的帖子。
Any way to do this? 有什么办法吗?
or.. if its easier.. from both a specific category AND a specific tag 或..如果更容易..既来自特定类别又来自特定标签
In a wp_query (I assume that's what you're wanting). 在wp_query中(我想这就是您想要的)。 You would use the following from the WP Class Reference for wp_query:
您可以将WP Class Reference中的以下内容用于wp_query:
$query = new WP_Query( array( 'category__and' => array( 2, 5 ) ) );
For a category and a tag, I assume you could get away with (UNTESTED): 对于类别和标签,我认为您可以使用(UNTESTED):
$args = array (
'cat' => 2,
'tag_id' => 5,
);
$query = new WP_Query($args);
You can view all wp_query arguments on the codex: https://codex.wordpress.org/Class_Reference/WP_Query 您可以在编解码器上查看所有wp_query参数: https ://codex.wordpress.org/Class_Reference/WP_Query
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.