• Resolved lzfy84

    (@lzfy84)


    Hi, I’ve created a custom post type and activated support for categories and set the option Has Archive to true. This worked well and I could view posts when clicking a category. But this stopped working as soon as I created a second custom post type. Now no custom post is shown under any category and I have no idea what I did wrong.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not quite sure how one would work in category archives, but none once a 2nd one is registered. I do have to wonder if this tutorial would help overall:

    https://docs.pluginize.com/article/17-post-types-in-category-tag-archives

    We don’t do anything special outside of actually registering, so a lot of things fall on the user after that, including setting the category/post_tag archives to include a custom post type as part of the query.

    Thread Starter lzfy84

    (@lzfy84)

    Like I said, it worked well with one custom post type and stopped working once I created a second one. Even after removing the second custom post type.

    Your link fixed the problem but it broke the menu in the theme so I’m assuming I did something wrong. Thanks for the help.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Shouldn’t have broken the menu, unless you removed the is_main_query() checks, which should be left to prevent menu breaking.

    Not quite sure that to say otherwise, at the moment. I don’t know what may have added the first post type to the archives, since WordPress doesn’t for any of them without being told to by a theme or plugin. CPTUI doesn’t, for what it’s worth.

    Thread Starter lzfy84

    (@lzfy84)

    I use the plugins CPT UI together with ACF and the theme GeneratePress. Not sure if it has anything to do with it.

    I have to ask a developer to fix the problem with the menu since my knowledge of PHP is very limited.

    Thread Starter lzfy84

    (@lzfy84)

    Btw, this code fixed my problem.

    function add_custom_types_to_tax( $query ) {
    if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    
    // Get all your post types
    $post_types = get_post_types();
    
    $query->set( 'post_type', $post_types );
    return $query;
    }
    }
    add_filter( 'pre_get_posts', 'add_custom_types_to_tax' );
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Sounds good. Not seeing any lingering issues at the moment, but feel free to chime in again if something comes up.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom posts not showing up under categories’ is closed to new replies.