ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Category Count is counting wrong?

January 20, 2010 5:02pm

Subscribe [3]
  • #1 / Jan 20, 2010 5:02pm

    mrpiano

    85 posts

    Howdy!

    I have this code in my blog:

    {exp:weblog:categories weblog="mainblog" show_empty="no" id="null2"}
    <h6><a href="http://{path=spotlight/blog}">{category_name}</a>
    
    {exp:query sql="SELECT count(exp_category_posts.entry_id) AS post_count
    FROM exp_category_posts WHERE exp_category_posts.cat_id = {category_id} "}
    ({post_count} entries)
    {/exp:query}
    
    </h6>
    <p>{/exp:weblog:categories}

    It’s returning the wrong number of posts across each category.

    Page is here

    Look on the sidebar at the bottom.  For what it’s worth, I put this code in my template when I had a bunch of other posts live on my blog.  So, the initial count being reflected was likely the number of posts I had live when I put the code in the template.  Then I went and “closed” those posts.  Now I have have 2 blog posts that are in 3 categories.

    It never updated.  I pulled the code out, refreshed the page, and the numbers remain.

    Any idea on why it won’t update?

    Thank you!

    GG

  • #2 / Jan 20, 2010 10:00pm

    Adam Dorsey

    1439 posts

    Hi-
    Check out this Wiki Article on the Category Count subject.

    The issue with your code, is that if a weblog entry is assigned to multiple categories, that will throw it off, and more importantly, it doesn’t take into account the status of the post, which is why your “closed” posts are still being returned.

    In that Wiki article, you will need to use something more like the top query, or make use of that plugin, in the article, which takes statuses into account.

    Does this help?

    Thanks!

  • #3 / Jan 21, 2010 10:39am

    mrpiano

    85 posts

    Ah, Adam, we meet again!

    Yep, that makes total sense.  I’ll look for another way to handle this per the links you provided.

    GG

  • #4 / Jan 21, 2010 2:50pm

    Ingmar

    29245 posts

    Glad to see that explains it for you. Please post again as needed.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases