1

I'm using the CPT UI plugin to create a custom post type with a custom taxonomy. I'm finding however that the individual post page shows "No Results Found".

I'm using this page slug as the CPT custom rewrite slug: wbc-activity-page

The terms page is working correctly on this url: domain.com/wbc-activity-page/home/

The issue is that the post page is showing 'no results found' on the post's url: domain.com/wbc-activity-page/wbc-post-1/

This is my post type settings:

    function cptui_register_my_cpts_wbc_activity() {

    /**
     * Post Type: WBC Activities.
     */

    $labels = [
        "name" => __( "WBC Activities", "mw-theme" ),
        "singular_name" => __( "WBC Activity", "mw-theme" ),
    ];

    $args = [
        "label" => __( "WBC Activities", "mw-theme" ),
        "labels" => $labels,
        "description" => "",
        "public" => true,
        "publicly_queryable" => true,
        "show_ui" => true,
        "show_in_rest" => true,
        "rest_base" => "",
        "rest_controller_class" => "WP_REST_Posts_Controller",
        "has_archive" => false,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "delete_with_user" => false,
        "exclude_from_search" => false,
        "capability_type" => "post",
        "map_meta_cap" => true,
        "hierarchical" => false,
        "rewrite" => [ "slug" => "wbc-activity-page", "with_front" => true ],
        "query_var" => true,
        "supports" => [ "title", "editor", "thumbnail", "custom-fields", "comments", "revisions" ],
        "taxonomies" => [ "wbc_category" ],
    ];

    register_post_type( "wbc_activity", $args );
}

add_action( 'init', 'cptui_register_my_cpts_wbc_activity' );

This is my custom taxonomy settings:

    function cptui_register_my_taxes_wbc_category() {

    /**
     * Taxonomy: WBC Activity Categories.
     */

    $labels = [
        "name" => __( "WBC Activity Categories", "mw-theme" ),
        "singular_name" => __( "WBC Activity Category", "mw-theme" ),
    ];

    $args = [
        "label" => __( "WBC Activity Categories", "mw-theme" ),
        "labels" => $labels,
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => true,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => [ 'slug' => 'wbc-activity-page', 'with_front' => true, ],
        "show_admin_column" => false,
        "show_in_rest" => true,
        "rest_base" => "wbc_category",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "show_in_quick_edit" => true,
        ];
    register_taxonomy( "wbc_category", [ "wbc_activity" ], $args );
}
add_action( 'init', 'cptui_register_my_taxes_wbc_category' );

Is there something I'm missing here?

3
  • Taxonomies and post types can't have the same rewrite slug. When you go to wbc-activity-page/wbc-post-1/, WordPress thinks wbc-post-1 is a taxonomy term, which is why it can't find any posts. They'll need to be different. Commented May 27, 2020 at 11:41
  • 1
    my understanding of the code above is that both the terms, and the posts share exactly the same URL structure, which is a big problem, e.g. if I visit domain.com/wbc-activity-page/home/ is that for a CPT with the slug home or a term with the slug home? You can't have clashes
    – Tom J Nowell
    Commented May 27, 2020 at 11:42
  • @JacobPeattie, thanks for this. If these have to be different, do you know how you would have the post and taxonomy term nested under the custom post type slug? Whenever I try to achieve this either the term or the single-post page shows no results found? (e.g. domain.com/custom-post-slug/taxomomy-term/post-title)
    – FreddieE
    Commented May 27, 2020 at 13:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.