• Josh

    (@modernspark)


    I’m trying to display the number of posts in a custom post type that are also in a specific taxonomy. All I want to do is display something as simple as this:

    24 Homes are For Sale
    50 Homes are Sold

    Right now I have custom post type “homes” and two “home status” taxonomy categories of “for sale” and “sold”.

    I can display the count for all posts of the custom post type “homes” using wp_count_posts, but I’m not sure how to get the count for ONLY the “for sale” or “sold” category under the “home status” taxonomy.

    Any help or ideas would be great! Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Here is some code that might help:

    https://pastebin.com/5yxwwR91

    Thread Starter Josh

    (@modernspark)

    Thanks for the response and code. Unfortunately, it didn’t work. I looked through the code to see if anything looked incorrect, but I think everything is referring to the right taxonomy and post type.

    It seems like there must be an easier way. All I really want to do is pull the number that’s showing in the categories/taxonomies section.

    Here’s a screenshot of the number I want to pull:

    https://dl.dropbox.com/u/17323120/Clients/screenshot.jpg

    Again, here’s the post type, taxonomy, and taxonomy options I am using:

    post_type = “homes”
    taxonomy = “home-status”
    home-status options = “for-sale” and “sold”

    Any additional help would be great! Thanks!

    There is one change in the code I posted. According to your latest info, his line:

    $labels = array('For Sale' => 'for sale', 'Sold' => 'sold');

    should be this:

    $labels = array('For Sale' => 'for-sale', 'Sold' => 'sold');

    I have tested the code and it should work if all terms are correct.

    Thread Starter Josh

    (@modernspark)

    It’s still not working for some reason. All it displays is the “homes are for sale” and “home is sold” part, so it’s not grabbing the quantity.

    Then one or more of ‘home-status’, ‘for-sale’ and ‘sold’ are probably not correct in the code.

    Please use this query to verify the post_type:

    SELECT DISTINCT post_type FROM wp_posts
    WHERE LOWER(post_type) LIKE '%home%'

    and this one to verify the taxonomy and terms:

    SELECT tt.taxonomy, t.name
    FROM wp_term_taxonomy tt, wp_terms t
    WHERE LOWER(tt.taxonomy) LIKE '%home%'
    AND tt.term_id = t.term_id
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Count Posts in Custom Post Type in Specific Taxonomy’ is closed to new replies.