gpt4 book ai didi

mysql - Wordpress SQL 与类别添加

转载 作者:行者123 更新时间:2023-11-30 00:11:22 24 4
gpt4 key购买 nike

我在一个插件中有一些 SQL,可以根据 WordPress 用户发表的帖子来选择他们。我遇到的问题还要求帖子来自某个类别。我已经查看了条款表,但没有进一步了解。

这是我迄今为止所掌握的 SQL 代码。

SELECT u.ID, u.user_nicename, u.display_name, u.user_email, p.post_date 
FROM $wpdb->users u
INNER JOIN (SELECT post_author, MAX(post_date) post_date
FROM $wpdb->posts
WHERE post_type = 'post' AND post_title != 'Auto Draft' AND post_title != '' AND post_status = 'publish'
GROUP BY post_author) p
WHERE u.ID = p.post_author
ORDER BY u.display_name

我想我想在查询中添加类似下面的内容,但我不确定。

AND $wpdb->term_taxonomy.taxonomy = 'category'

最佳答案

试试这个:

SELECT u.ID, u.user_nicename, u.display_name, u.user_email, p.post_date, p.ID, ktt.taxonomy, kct.Name
FROM kc_users u
INNER JOIN (SELECT post_author, MAX(post_date) post_date, ID
FROM kc_posts
WHERE post_type = 'post' AND post_title != 'Auto Draft' AND post_title != '' AND post_status = 'publish'
GROUP BY post_author) p
INNER JOIN kc_term_relationships ktr ON ktr.object_id = p.ID
INNER JOIN kc_term_taxonomy ktt ON ktt.term_id = ktr.term_taxonomy_id
INNER JOIN kc_terms kct ON kct.term_id = ktt.term_id
WHERE u.ID = p.post_author
AND ktt.taxonomy = 'category'
-- AND kct.Name = 'your description filter' <- Filter here
ORDER BY u.display_name

显然您的表名前缀将与我的不同

关于mysql - Wordpress SQL 与类别添加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24018123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com