• WordPress version: 5.3.2

    I’m using what I believe to be a built in WordPress widget, the categories widget. Options include

    Title
    Display as dropdown
    Show post counts
    Show hierarchy

    When displaying the sidebar, most post counts are fully duplicated, or at least overinflated compared to the actual number of posts in that category. Currently [ redundant link removed ] only shows a single post on the archive page, but the Category widget at the bottom right of the page indicates there should be two posts. This is happening on almost every category, but not all of them.

    1) How can I determine why this is happening?
    2) Is there a setting I’m missing which allows me to exclude duplicates?

    • This topic was modified 6 years, 6 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    That does sound like the core widget. I’ve not observed a similar problem on my site, so it could be the result of your theme or a plugin. Are you sure there are no other post types that might be assigned category terms, maybe hidden or private?

    Anyway, narrow down the source of the bad counts. Switch to twentytwenty theme and deactivate all plugins. The widget should show correct counts if the page is not cached. Restore your theme and plugins one at a time, checking the counts after each. When bad counts return, the last activated module is the cause. Ask the devs of the responsible module for advice on correcting the issue.

    Thread Starter commadelimited

    (@commadelimited)

    @bcworkz thanks! I am a software engineer, but the inner workings of WP are a mystery to me. 😀

    This is good debugging skills for this issue, and for other issues.

    Is there a way I can determine if the database might be at issue? Perhaps it’s just duplicate data somewhere?

    • This reply was modified 6 years, 6 months ago by commadelimited. Reason: added question
    Moderator bcworkz

    (@bcworkz)

    Oh! That’s a good thought. I was thinking WP core did a count query, but there is a specific count column in the term taxonomy table. Determine the category term’s ID from the edit link URL parameters. The edit link that shows up on roll over of the admin category list table. Use phpMyAdmin to examine the table and locate the term’s ID and its corresponding count. Maybe that value got corrupted somehow. Either that or the relations in term relationships table are messed up. Search for that term’s taxonomy ID in term relationships, which might or might not be the same as term ID. See how many objects come up in search and see if they match the count value.

    BTW, inner workings of WP are a mystery to almost everyone, you’re in good company 🙂

    Thread Starter commadelimited

    (@commadelimited)

    A few odd things.

    In the edit bar on the American West category, I see “Edit board game category” instead of simply “Edit category”. Is that a concern? When I click in to edit that category I see this URL: taxonomy=category&tag_ID=1278.

    Here’s some of the corresponding data:

    
    select * from wp_term_taxonomy where term_id = 1278
    -- term_tax_id	term_id	tax	desc	parent	count
    -- 1278	1278	category	""	0	2
    
    select * from wp_term_taxonomy where taxonomy = 'American West' or description  = 'American West'
    -- no results
    
    select * from wp_termmeta where meta_key = 'American West' or meta_value  = 'American West'
    -- no results
    
    select * from wp_terms where name = 'American West'
    -- term_id	name	slug	term_group
    -- 1278	American West	american-west	0
    
    select * from wp_term_relationships where term_taxonomy_id = 1278
    -- object_id	term_taxonomy_id	term_order
    -- 2495	1278	0
    -- 3905	1278	0
    -- 3906	1278	0
    -- 3908	1278	0
    -- 8173	1278	0
    
    Moderator bcworkz

    (@bcworkz)

    The text you see in the UI are simply labels, so aren’t that concerning to me. It’s a little strange to take over the built in category taxonomy like that. Maybe even considered bad practice, but on its own would not explain improper count values. Most devs who want to have their own taxonomy for some purpose would create a new one, not take over the built in category taxonomy. However, it is a clue towards the extra count item.

    At least the widget is behaving correctly despite you only seeing one post and there being 5 listed objects. The extra objects could be draft or backup posts that would not contribute to the count. You would need to check the posts table and locate the respective object IDs as post ID to determine the nature of each post.

    You’ll find the one post listed on the archive page. There is probably another published object of a different post type that brings the count up to two. Data for a board game perhaps? The rest likely have draft or inherit (backup) post status that are assigned a category term but do not count towards the 2 count total shown in term taxonomy and in the widget.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Categories widget post count incorrect (doubled)’ is closed to new replies.