【问题标题】:Get a list of the last posts grouped by author and filtered by category获取按作者分组并按类别过滤的最新帖子列表
【发布时间】:2014-07-16 17:33:33
【问题描述】:

我需要一个由不同作者发布的最新帖子列表,但按类别过滤,例如有关音乐的作者的最新帖子。

我写了这个查询,看起来像在 mysql 中工作

SELECT * FROM
(
    SELECT * 
    FROM $wpdb->posts
    INNER JOIN 
        wp_term_relationships ON $wpdb->posts.ID = wp_term_relationships.object_id
    WHERE 
        wp_term_relationships.term_taxonomy_id = 7
        AND
        $wpdb->posts.post_status = 'publish'

    ORDER BY $wpdb->posts.post_date DESC
)
AS x GROUP BY post_author

(7 只是一个示例类别 ID)

我只是想知道调用wp_term_relationships 表的其他$wpdb 函数以及此查询是否有问题

提前谢谢你

【问题讨论】:

    标签: php mysql wordpress


    【解决方案1】:

    怎么样

    $args = array(
        'post_type' => 'post',
        'cat' => $category_id,
    );
    
    $wp_query = new WP_Query($args);
    

    【讨论】:

    • 感谢您的回答,但这不是重点,我需要按类别过滤的每个作者的最后一篇文章
    猜你喜欢
    • 1970-01-01
    • 2020-11-10
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    相关资源
    最近更新 更多