Support » Fixing WordPress » Separate categories being lumped together

  • Resolved Ate Up With Motor


    I’m having a peculiar problem. I have posts grouped into several categories, some of which are divided into subcategories.

    If I look at the categories assigned to each post, they appear to be correct. If I look at the Posts–>Categories menu, the number of posts under each article is correct.

    However, certain categories are being lumped together any time I try to filter by category in the admin Posts list, if you click on a category from the front end, and also on the HTML sitemap (which generates a list of posts grouped by category).

    Here’s a specific example: Many posts are in the parent category Model Histories, which has several subcategories, including Family Cars and Luxury Cars. There are 24 posts in Family Cars and 40 in Luxury Cars. If I go to the All Posts screen, click Filter by Category, and select “Luxury Cars,” I get 64 results: all the Luxury Cars posts AND all the Family Cars posts. The same happens in the sitemap or if someone clicks either of those categories from the front end.

    I’ve never seen this before and I don’t have a clue what might be causing it or how to fix it. Does anyone have any suggestions? I’m baffled.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Can you post a link where we can see this happening?

    You can see the example mentioned above on the category page here and also the site map.

    If you scroll down the category page a bit, you’ll see that it includes posts that are part of the Family Cars category, which should not be on this page at all; they’re lumped together on the site map as well. However, the converse is not true: If you go to the Family Cars category page (here), you’ll see that it does not include any posts from the Luxury and Personal Luxury Cars category (which is as it should be).

    When did you first notice this? Was there an update or anything when this first started happening or is this a new site? Are you sure that those posts are not in both categories?

    This is after a migration from another CMS. I imported content to a new WordPress site, cleaned it up, and then moved that to the live domain. I believe it occurred sometime after the latter move, although I’m not positive.

    I am quite certain that those posts are not in both categories. Also, as I noted in my original post, if I look at the Categories page in the back end, each affected category shows the correct number of posts, and if I look at each individual post, it shows only the correct category, but for some reason, WordPress is putting them together when asked to sort or filter by one of the affected categories.

    How are you displaying the posts? Can you post the code that loops through to show those categories?

    For the posts themselves, it’s this:

    <div class="entry-byline">
    		$post_elements = frontier_option('post_elements');
    		$page_elements = frontier_option('page_elements');
    		if ( !isset($post_elements['author']) ) $post_elements['author'] = 1;
    		if ( !isset($post_elements['published']) ) $post_elements['published'] = 1;
    		if ( !isset($post_elements['categories']) ) $post_elements['categories'] = 1;
    		if ( !isset($post_elements['comment_info']) ) $post_elements['comment_info'] = 1;
    		if ( !isset($post_elements['updated']) ) $post_elements['updated'] = 1;
    		if ( !isset($post_elements['tags']) ) $post_elements['tags'] = 1;
    		if ( !isset($post_elements['post_nav']) ) $post_elements['post_nav'] = 1;
    		if ( !isset($post_elements['author_box']) ) $post_elements['author_box'] = 0;
    		if ( !isset($post_elements['comments']) ) $post_elements['comments'] = 1;
    		if ( !isset($page_elements['author']) ) $page_elements['author'] = 0;
    		if ( !isset($page_elements['published']) ) $page_elements['published'] = 0;
    		if ( !isset($page_elements['comment_info']) ) $page_elements['comment_info'] = 0;
    		if ( !isset($page_elements['updated']) ) $page_elements['updated'] = 0;
    		if ( !isset($page_elements['author_box']) ) $page_elements['author_box'] = 0;
    		if ( !isset($page_elements['comments']) ) $page_elements['comments'] = 1;
    	<?php if ( ( is_singular('post') && $post_elements['author'] == 1 ) || ( is_page() && $page_elements['author'] == 1 ) ) : ?><div class="entry-author"><i class="genericon genericon-user"></i><?php the_author_posts_link(); ?></div><?php endif; ?>
    	<?php if ( ( is_singular('post') && $post_elements['published'] == 1 ) || ( is_page() && $page_elements['published'] == 1 ) ) : ?><div class="entry-date"><i class="genericon genericon-day"></i><a href="<?php the_permalink(); ?>"><?php the_time(get_option('date_format')); ?></a></div><?php endif; ?>
    	<?php if ( is_singular('post') && $post_elements['categories'] == 1 ) : ?><div class="entry-categories"><i class="genericon genericon-category"></i><?php the_category(', '); ?></div><?php endif; ?>
    	<?php if ( ( is_singular('post') && $post_elements['comment_info'] == 1 ) || ( is_page() && $page_elements['comment_info'] == 1 ) ) : ?><div class="entry-comment-info"><i class="genericon genericon-comment"></i><a href="<?php the_permalink(); ?>#comment-area"><?php comments_number( __('Comments', 'frontier'), __('1 Comment', 'frontier'), __('% Comments', 'frontier') ); ?></a></div><?php endif; ?>
    	<?php edit_post_link( __('Edit', 'frontier'), '<i class="genericon genericon-edit"></i>' ); ?>

    (The if statements are because the theme allows you to toggle whether you want the categories to display or not.)

    For the sitemap, it’s this:

    $cats = get_categories('exclude=3,11');
    foreach ($cats as $cat) {
      echo "<h3>".$cat->cat_name."</h3>";
      echo "<ul>";
      $archive_query = new WP_Query('posts_per_page=-1&order=asc&orderby=title&cat='.$cat->cat_ID);
      while ($archive_query->have_posts()) { $archive_query->the_post();
        $category = get_the_category();
    	  echo '<li><a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a></li>';
      echo "</ul>";

    What theme are you using?

    A child theme off Frontier.

    Hmmm…. not sure. Maybe something was corrupted in the migration. Maybe others can assist with some ideas. Have you posted in the theme forum?

    Here’s another curious fact. I tried to add a new category with Model Histories as a parent and then assign one of the posts in the affected categories to that new subcategory. WordPress would not let me assign it to the newly created category. I could click the checkbox for it and hit Update, but as soon as I did, the checkbox disappeared and the category information was not saved. I found I could remove and add back one of the existing subcategories, but not a newly created one.

    I think there’s something more basic (and pretty serious) going on. If I create a new category, I can’t add posts to it (if I try to check the box for that category from the edit window, it unchecks as soon as I hit Update) and I can’t delete it without going into the table and dropping that row. If I try to delete the category from the Categories menu, it flashes red and disappears, but if I refresh or if I navigate elsewhere and then go back, the category is still there (and still in the table).

    I tried deactivating all plugins and switching to the unmodified Twenty Thirteen theme and trying again to assign a post to a new category or delete a category. Same result: I can create the category, but I can’t assign posts to it and can’t delete it.

    I’m not sure what else I can try.

    Okay, it appears what happened was that when the data was imported, the parameters and indices of the term_relationships and term_taxonomy tables were not set properly, so neither of those tables had an index. I fixed that — with considerable difficulty — and that solved all of these problems. Apparently the tables not being indexed left WordPress unclear on what to do with them.

    Glad you got it figured out.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Separate categories being lumped together’ is closed to new replies.