列出在Wordpress中已在类别/标签中写入特定数量帖子的作者

Kru*_*nal 2 wordpress wordpress-theming wordpress-plugin

我正努力在类别页面上获取作者列表.我需要列出撰写该类别至少5篇文章的作者.

我也需要在标签中使用这样的东西.

知道怎么在wordpress中这样做吗?

Bai*_*net 7

它只能用于自定义SQL查询,所以这里是一个简单的函数,它应该返回一个数组,其中用户id的用户在当前术语存档中至少有$ n个帖子,这意味着它应该在类别,标签和自定义分类中工作

function get_authors_with($num = 5){
    global $wpdb;
    $term_slug = get_query_var( 'term' );
    $taxonomyName = get_query_var( 'taxonomy' );
    $current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
    $sub_q = $wpdb->prepare("SELECT * FROM $wpdb->posts
            INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)
            INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
            WHERE ($wpdb->term_taxonomy.term_id = %s
            AND $wpdb->term_taxonomy.taxonomy = '%s'
            AND $wpdb->posts.post_type = 'post'
            AND $wpdb->posts.post_status = 'publish')",
        $current_term->term_id,
        $taxonomyName
    );
    $sql = $wpdb->prepare("SELECT $wpdb->posts.post_author, FROM (%s)
            GROUP BY $wpdb->posts.post_author
            HAVING count(*) > %s",
            $sub_q,
            $num
    );
    return $wpdb->get_results($sql);
}
Run Code Online (Sandbox Code Playgroud)