• Resolved immewnity

    (@immewnity)


    In over a decade of working with WordPress, I’ve never seen this issue happen… a post is showing up on the category archive page of a category it’s not categorized in.

    For context (I’d link if the site were public): post is of a custom post type (rulings), and has the ID 343. The two categories it is in have IDs of 9004 and 806, with 9004 being the parent of 806. The category where the post is incorrectly appearing in is 9008. I checked wp_term_relationships and wp_term_taxonomy, and neither shows 9008 being associated with any of the other IDs.

    And yes, it persists with all plugins disabled.

    It appears that category 806 is the issue, as adding that category to other posts make them show on 9008, and removing that category from 343 removes it from the category. However, if I view the category via API (/wp-json/wp/v2/rulings?categories=9008), everything looks fine – no post 343 regardless of the presence of 806.

    Any ideas?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter immewnity

    (@immewnity)

    Some additional info, after further research with Query Monitor. The issue appears to come down to this query:

    SELECT t.*, tt.*
    FROM cpdm_terms AS t
    INNER JOIN cpdm_term_taxonomy AS tt
    ON t.term_id = tt.term_id
    WHERE tt.taxonomy IN ('category')
    AND t.term_id IN ( 185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,806,9008 )

    Of those category IDs, only 185-193 are actually children of 9008, the rest are other categories (none of which are related to 9008 in any way). This is, however, the correct quantity of child categories. In reality, 177-193 and 801 are the children of 9008. So, somehow, it’s choosing to pull the wrong categories in…

    “a post is showing up on the category archive page”

    “However, if I view the category via API (/wp-json/wp/v2/rulings?categories=9008), everything looks fine ”

    You mentioned plugins, but not themes. Have you switched to default theme, as at first glance I would guess a theme / archive template issue

    Thread Starter immewnity

    (@immewnity)

    Just tried it in vanilla Twenty Twenty-One, same basic issue:

    SELECT SQL_CALC_FOUND_ROWS cpdm_posts.ID
    FROM cpdm_posts
    LEFT JOIN cpdm_term_relationships
    ON (cpdm_posts.ID = cpdm_term_relationships.object_id)
    WHERE 1=1
    AND ( cpdm_term_relationships.term_taxonomy_id IN (185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,806,9008) )
    AND cpdm_posts.post_type = 'post'
    AND (cpdm_posts.post_status = 'publish'
    OR cpdm_posts.post_status = 'private')
    GROUP BY cpdm_posts.ID
    ORDER BY cpdm_posts.post_date DESC
    LIMIT 0, 10
    Thread Starter immewnity

    (@immewnity)

    Okay, so, if I change to a custom taxonomy instead of the built in “categories”, it shows fine, and the only ID that shows in the SQL query is the parent ID. So there’s some issue with the “category” taxonomy…

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

The topic ‘Post appearing in category archive when it shouldn’t’ is closed to new replies.