我偶然发现了同样的问题,并通过请求MySQL解决了它。
简而言之:get\\u post($args)将返回类别为MyCategory的帖子OR 标记=MyTag。
你想要的是改变你的OR 到AND .
我的逻辑是直接使用MySQL查询:
查询1=选择所有具有类别MyCat的帖子查询2=选择所有具有标记MyTag的帖子最后:选择查询1和查询2中的所有帖子我使用wpdb 而不是query\\u post();
A bit of code (返回类别为MyCat和标记为MyTag的已发布帖子):
$query_byTag="
SELECT wp_posts.ID
FROM wp_posts, wp_term_relationships, wp_terms
WHERE wp_posts.ID = wp_term_relationships.object_id
AND wp_terms.term_id = wp_term_relationships.term_taxonomy_id
AND wp_terms.name = \'MyTag\'";
$query_byCat="
SELECT wp_posts.ID
FROM wp_posts, wp_term_relationships, wp_terms
WHERE wp_posts.ID = wp_term_relationships.object_id
AND wp_terms.term_id = wp_term_relationships.term_taxonomy_id
AND wp_terms.name = \'MyCat\'";
$query ="
SELECT wp_posts.post_title AS title ,
wp_posts.post_content AS content,
wp_posts.post_date AS blogdate
FROM wp_posts
WHERE wp_posts.post_status = \'publish\'
AND wp_posts.ID IN (".$query_byTag.")
AND wp_posts.ID IN (".$query_byCat.")
ORDER BY wp_posts.post_date DESC ";
$result= $wpdb->get_results($query);
这是一种肮脏的做法,但我希望它能有所帮助=)