添加类别的Wordpress SQL

时间:2014-06-03 14:42:00

标签: mysql sql wordpress

我在插件中有一些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'

1 个答案:

答案 0 :(得分:0)

试试这个:

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

显然,您的表名前缀与我的

不同