WordPress.org

Forums

count_user_posts_by_taxonomy (4 posts)

  1. AliMH
    Member
    Posted 2 years ago #

    hi i know there is a fuction like count_user_posts_by_type and even a patch for it for post type, but is there anything for taxonomies? i really need to get tho authors per taxonomy. is there a query ?

  2. bcworkz
    Member
    Posted 2 years ago #

    Yes there is a query, but it gets rather complex, as several table joins are required. In plain english using SQL logic, you want a count of distinct users who are authors of posts associated with a particular taxonomy where the term is 'whatever'. Unfortunately, my SQL skills prevent me from providing a workable query. Maybe someone else will be able to help you, but at least you know it's possible.

    If that's too mind boggling, you could use WP_Query to retrieve all posts associated with a taxonomy term, then use code to tally up the number of distinct authors. Very inefficient compared to SQL, but fairly easy to code. The only challenge is ensuring you are incrementing the counter only when a author hasn't been counted yet.

  3. AliMH
    Member
    Posted 2 years ago #

    thanks bcworkz i know i can query all posts and then count em but i use another way, i'm developing a site with no post therefor i add my own hook to add count to user meta when user create a new post defined taxonomy, its way efficent and way better than any other solutions.

  4. AliMH
    Member
    Posted 2 years ago #

    anyway if someone able to add this query it will useful for future, maybe someone need it.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.