[Resolved] Question on archive for custom taxonomy

Home Forums Support [Resolved] Question on archive for custom taxonomy

Home Forums Support Question on archive for custom taxonomy

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #861005
    Henry

    Hi, I created custom taxonomy using WordPress Pods, which works great.

    However, I notice that if you visit the root of that custom taxonomy there is an error 404, i.e. there is no archive.

    My custom taxonomy is ‘US States’ for, (hardly surprising) data that I’ve placed within US States! So, the actual slug is like this us-states

    According to the WordPress hierarchy, I can create a template called: taxonomy-us-state.php however if I upload this to my server it doesn’t load – it continues to throw the Error 404.

    So, my question is – where do I place this template? Is there a resource you can share to show me how to create custom taxonomy templates? Thanks!

    #861461
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Have you tried re-saving your permalinks yet? If not, go to “Settings > Permalinks” and hit the save button. That can sometimes fix this issue.

    Let me know ๐Ÿ™‚

    #861647
    Henry

    thanks Tom, but no joy.

    If I apply a standard WordPress category to my Custom Post Type it doesn’t show within the archive page.

    If I create and apply a standard WordPress post with the same category that post shows as expected within the archive page.

    What’s your hunch how to fix this? Is it a GP thing?

    #862128
    Tom
    Lead Developer
    Lead Developer

    Custom taxonomies/post types are a WordPress thing. They can be tricky sometimes.

    Does this custom taxonomy apply to regular posts, or is there a custom post type?

    #862356
    Henry

    Thanks Tom – in fact I fixed it with help from the Pods community. Here’s the code that I used to ‘normalize’ the behavior of WordPress to call in the archive of CPT’s:

    add_action( 'pre_get_posts', function ( $q )
    {
        if (  !is_admin() // Only target front end queries
              && $q->is_main_query() // Only target the main query
              && $q->is_category()   // Only target category archives
        ) {
            $q->set( 'post_type', ['post','custom_post_1', 'custom_post_2', 'custom_post_3'] );    }
    });

    ^ The above came from Pods: https://docs.pods.io/code-snippets/modifying-pre_get_posts-categories-tags-show-custom-post-types/

    #862367
    Tom
    Lead Developer
    Lead Developer

    Awesome! Glad you got it working ๐Ÿ™‚

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.