我正在使用下面的查询输出自定义分类中的所有链接。它输出所有标记为“http”的分类“单词”的帖子。
我想从输出中排除一些常规类别。所以,fe。它只输出媒体和新闻类别中的链接。实现这一目标的最佳方法是什么?
$wp_query->request = "
SELECT DISTINCT *
FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
WHERE $wpdb->posts.post_type = 'post'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->term_taxonomy.taxonomy = 'words'
AND $wpdb->terms.slug = 'http'
ORDER BY $wpdb->posts.post_date DESC
LIMIT $ppp OFFSET $offset";
$pagelinkposts = $wpdb->get_results($wp_query->request, OBJECT);
答案 0 :(得分:0)
我通过使用另一个插件的代码以某种方式自己找到了解决方案。如果其他人想要达到同样的效果,请在ORDER BY行之前添加以下内容(并将category-id更改为您想要包含的内容。)
AND object_id IN
(
SELECT object_id
FROM $wpdb->term_relationships AS r
JOIN $wpdb->term_taxonomy AS x ON x.term_taxonomy_id = r.term_taxonomy_id
JOIN $wpdb->terms AS t ON t.term_id = x.term_id
WHERE x.taxonomy = 'category'
AND t.term_id IN (category-ids))