Custom Taxonomy Archive Not Showing All Child Terms (3 posts)

  1. Curtiss Grymala
    Posted 3 years ago #

    I'm trying to develop a plugin that implements custom post types and custom taxonomies. The custom taxonomies are all hierarchical. Archive pages for top-level taxonomies should be showing posts that belong to all of their children. However, at the moment, they only seem to be showing posts that belong to one of the taxonomy's children, and stopping there.

    I've checked my error logs, and am not seeing anything to indicate why it's only pulling one child term.

    For instance, I have one top-level taxonomy that has 2 posts assigned to it. Then, there are four terms that are direct descendants of that top-level term. The first and third children have 2 posts each, the second has 7 posts, and the fourth has 5 posts. Only the fourth term is being included in the archive for that top-level term (along with the 2 posts that belong directly to that top-level term). None of the other child terms are showing up on the page.

    Do you guys have any thoughts as to why the query seems to be skipping over the first three child terms?

    The only way I am modifying the query is to pull the posts in ascending alphabetical order (by using the pre_get_posts action and the set_query_var() method). I've even tried pulling that code out, and it still only shows the fourth child term on that archive page.

    I've pasted the relevant code into a Pastebin, in case anyone wants to take a look. Thanks.


  2. Seebz
    Posted 3 years ago #

    Try this :

    $query->set('orderby', 'title');
    $query->set('order', 'ASC');


    $query->query_vars['orderby'] = 'title';
    $query->query_vars['order'] = 'ASC';
  3. Curtiss Grymala
    Posted 3 years ago #

    I found the issue. In converting posts from the "post" post type to a custom post type, and converting the terms from the "category" taxonomy to a custom taxonomy, WordPress apparently got confused somewhere along the way and kept some post IDs associated with the "category" taxonomies. Therefore, the archive pages, even though they should have been showing members of the "department" taxonomy, were showing only the posts that were still associated with the old "category" with the same name.

    Obviously I messed something up in the logic of my converter (most likely due to the fact that I have to perform the conversion in small chunks in order to avoid timing out).

    It seems that editing the child terms and saving them (without making any changes) fixes the issue.

Topic Closed

This topic has been closed to new replies.

About this Topic