• Resolved dankfresh

    (@dankfresh)


    I am inheriting a site using CPT UI and I am much more used to using register_post_type() and register_taxonomy() to accomplish these tasks. Nevertheless, I like the plugin but it seems the archive/category/taxonomy templates do not have a working loop.

    For example, I have a post type “Webinars”. The custom taxonomy for that post type is “Webinar Category”.

    I have tried to use:

    archive.php
    taxonomy.php
    taxonomy-webinar_category.php

    And a very simple:

    <?php get_header(); ?>
    <?php if (have_posts()): while (have_posts()) : the_post();
    	echo the_title(); 
    endwhile; endif; ?>
    <?php get_footer(); ?>

    in the actual files themselves, just to debug. When I visit www.mysite.com/webinar_category/any-taxonomy-term/ the loop is always empty and nothing shows even though I know there are posts within the taxonomy. This happens for every taxonomy created through CPT UI, any term.

    Is there a setting in the CPT UI settings that controls whether the loop will work? I have saved permalinks several times.

    Below is the JSON for the taxonomy

    {
    "webinar_category": {
        "name": "webinar_category",
        "label": "Webinar Categories",
        "singular_label": "Webinar Category",
        "description": "",
        "public": "true",
        "hierarchical": "true",
        "show_ui": "true",
        "show_in_menu": "true",
        "show_in_nav_menus": "true",
        "query_var": "true",
        "query_var_slug": "",
        "rewrite": "true",
        "rewrite_slug": "",
        "rewrite_withfront": "1",
        "rewrite_hierarchical": "0",
        "show_admin_column": "false",
        "show_in_rest": "false",
        "show_in_quick_edit": "",
        "rest_base": "",
        "labels": {
          "menu_name": "",
          "all_items": "",
          "edit_item": "",
          "view_item": "",
          "update_item": "",
          "add_new_item": "",
          "new_item_name": "",
          "parent_item": "",
          "parent_item_colon": "",
          "search_items": "",
          "popular_items": "",
          "separate_items_with_commas": "",
          "add_or_remove_items": "",
          "choose_from_most_used": "",
          "not_found": "",
          "no_terms": "",
          "items_list_navigation": "",
          "items_list": ""
        },
        "object_types": [
          "webinar"
        ]
    }

    Thanks!

    • This topic was modified 2 years, 7 months ago by dankfresh.
    • This topic was modified 2 years, 7 months ago by dankfresh.
    • This topic was modified 2 years, 7 months ago by dankfresh.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’m curious what the WP_Query request is for these, what’s it interpreting that it should be querying for. https://www.ads-software.com/plugins/query-monitor/ would be a good plugin to help with that part.

    Nothing in the JSON spot looks off or wrong, and we don’t have any custom settings that are meant to toggle archive status. We match up with the arg structure for register_post_type and register_taxonomy.

    Do you have any usage of the pre_get_posts hook that may be amending queries accidentally?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Did you ever get this figured out @dankfresh ?

    Thread Starter dankfresh

    (@dankfresh)

    So… maybe I’ve lost my mind but I always thought that if you put has_archive => true when registering the post type, the custom taxonomies associated with the post type would all work in the default loop when using the archive.php and taxonomy.php templates.

    Maybe I’m wrong?

    I ended up having to use a pre_get_posts filter in my functions.php file to have them all populate the way I expected:

    add_action( 'pre_get_posts', function( WP_Query $query ){
        if ( $query->is_main_query() && $query->is_tax(['my_custom_taxonomy'])) {
            $query->set( 'post_type', 'my_custom_post_type' );
        }
    });

    Still surprised I had to do that — I really thought registering a custom post-type/taxonomy would populate those templates automatically. Someone on another thread mentioned that the “loop” doesn’t know which post type to query in a taxonomy.php template, but… that’s why you put "taxonomies" => [ "my_custom_taxonomy" ], argument in the register_post_type args right?

    Oh well haha… I appreciate your help.

    • This reply was modified 2 years, 6 months ago by dankfresh.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I believe that is the way it’s supposed to work, but it’s also possible that other things unseen may have been affecting the queries as well.

    Anyways, you’re in a good place with this, which is awesome.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Archive/Category/Taxonomy Template Loop Not Working’ is closed to new replies.