• tikimojo

    (@tikimojo)


    Hello everyone. I’m working on updating the blog I started about my daughter before she was born and she’s 13 now. When I started, it didn’t occur to me to set up post categories so visitors could just to link to the posts for the right year. Over time I accumulated 857 uncategorized posts…

    I couldn’t find a plugin that would let me assign categories to posts based on date, so with some help I put together an SQL statement that does just that:

    UPDATE wp_term_relationships
    SET term_taxonomy_id = (SELECT term_taxonomy_id FROM wp_rfowje_term_taxonomy WHERE term_id = '20')
    WHERE object_id IN (
    SELECT p.ID FROM wp_posts p
    WHERE p.post_date LIKE '2009%' AND p.post_status = 'publish'
    )
    AND term_taxonomy_id = (
    SELECT term_taxonomy_id FROM wp_term_taxonomy
    WHERE term_id = (SELECT term_id FROM wp_terms WHERE name = 'Uncategorized')
    );

    This works quite well, and I can see in the WP UI that the posts are no longer ‘Uncategorized’ and are now ‘2009’. The thing I can’t figure out is that when I tell the sidebar widget to show post counts for the categories … the count is clearly wrong.

    It’s not a terribly big deal, but I like to get things right. Seems like there’s another place where something has to change to get the post count right. Any idea what that is?

    Thanks for your help,

    • Steve

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The post count for each term is saved in the term_taxonomy table. Your SQL query doesn’t appear to update this column, so it’s likely why the counts are no longer valid.

    For each term, determine how many times its term_taxonomy_id occurs in the term_relationships table. This is what the count value should be. If you don’t have too many terms to evaluate, this could be done manually through the phpMyAdmin app. I’m confident there’s a way to do this via some SQL query, but I couldn’t even begin to suggest how that would be accomplished.

Viewing 1 replies (of 1 total)
  • The topic ‘Category post counts incorrect’ is closed to new replies.