从自定义分类输出中排除类别
我使用下面的查询来输出自定义分类中的所有链接。它输出分类法“words”中标记为“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);
I'm using the query below to output all links from a custom taxonomy. It outputs all posts that are tagged 'http' from the taxonomy 'words'.
I would like to exclude some general categories from the output. So, fe. it only outputs links in the media and news categories. What would be the best way to achieve this?
$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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用另一个插件的代码以某种方式自己找到了解决方案。如果其他人想要实现相同的目标,请在 ORDER BY 行之前添加以下内容(并将类别 ID 更改为您想要包含的类别 ID。)
I somehow found the solution myself by using codes from another plugin. If someone else want to achieve the same thing add the below before the ORDER BY line (and change category-ids to the ones you want to include.)