• Resolved haagendazs1

    (@haagendazs1)


    Hi

    I’m trying to make a query to find out how many posts each “Contributor” has made within a category (ID=5). just to be clear, “Contributor” has a “wp_user_level” of “1”

    I have something like this so far

    SELECT DISTINCT COUNT(wp_posts.post_author) as thecount
    FROM wp_users INNER JOIN wp_usermeta ON (wp_users.ID = wp_usermeta.user_id), wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) LEFT JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
    WHERE wp_term_relationships.term_taxonomy_id IN (5)
    AND wp_usermeta.meta_key = ‘wp_user_level’
    AND wp_usermeta.meta_value = ‘1’
    AND wp_posts.post_status = ‘publish’
    AND wp_posts.post_type = ‘post’
    GROUP BY wp_posts.post_author
    ORDER BY thecount DESC

    Then after this I have a foreach thing going, but when I output the $variable->thecount, it outputs the total number of posts that exist in category(5) rather than the number that specific Contributor has posted

    Any help is greatly appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter haagendazs1

    (@haagendazs1)

    I’ve tried many different things to do this! I know it can be done before I have another code like this, very similar, but slightly different, and that works. but for some reason no matter how I manipulate this one, it keeps giving me the total number of posts in the category rather than the total number of posts in the category that the specific contributor has made. ??

    Thread Starter haagendazs1

    (@haagendazs1)

    Is there any way to have a count with a having or where or in clause?

    I’m trying to do something like
    COUNT(
    wp_posts.ID WHERE wp_term_relationships.term_taxonomy_id IN (5)) as thecount

    or something to that effect. The point is that I’m trying to count how many posts a user has in a specific category (id=5). Can some SQL expert help me?? ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query number posts contributor has made’ is closed to new replies.