• Resolved pepperstreetuk

    (@pepperstreetuk)


    I have created a custom post type TEAMS and it has categories and tags. The categories are U7, U8, U9 etc and each category has 3 or 4 teams assigned to it. I can see all the posts on a posts page but the URL https://bollingtonunited.co.uk/category/u7/ simply returns NO RESULTS FOUND. I’ve tried to add a couple of suggested functions to the functions.php but nothing seems to work I can’t get the category/U7 to display any results could someone help please? Really stuck.

    has_archive=”true” BTW

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

    (@tw2113)

    The BenchPresser

    Hi @pepperstreetuk

    It sounds like the archives aren’t including the custom post type in their queries, which is a default behavior for WordPress.

    We have https://docs.pluginize.com/article/post-types-in-category-tag-archives/ written up to help with this topic, but let me know if you’ve already tried similar things like this and we can see about troubleshooting the code you’ve tried thus far.

    Thread Starter pepperstreetuk

    (@pepperstreetuk)

    Hi thanks for the reply yes I have read this post. I tried both pieces of code individually. I used the second piece of code and replaced the array (I also tried the first piece of code still nothing) using DIVI theme if that help?

    function my_cptui_add_post_types_to_archives( $query ) {
    	// We do not want unintended consequences.
    	if ( is_admin() || ! $query->is_main_query() ) {
    		return;    
    	}
    
    	if ( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    
    		// Replace these slugs with the post types you want to include.
    		$cptui_post_types = array( 'team' );
    
    		$query->set(
    	  		'post_type',
    			array_merge(
    				array( 'post' ),
    				$cptui_post_types
    			)
    		);
    	}
    }
    add_filter( 'pre_get_posts', 'my_cptui_add_post_types_to_archives' );

    ‘team’ is my post type slug and also the tem that appears when I roll over the new custom post type in the backend so I’m fairly sure that’s right. Below is the code I have in my function.php to register the new post type (copied from the Custom POst Type plugin) But I still get the NO RESULTS FOUND when I go to the category page

    function cptui_register_my_cpts() {
    
    	/**
    	 * Post Type: Teams.
    	 */
    
    	$labels = [
    		"name" => esc_html__( "Teams", "custom-post-type-ui" ),
    		"singular_name" => esc_html__( "Team", "custom-post-type-ui" ),
    		"menu_name" => esc_html__( "BU Teams", "custom-post-type-ui" ),
    		"all_items" => esc_html__( "All Teams", "custom-post-type-ui" ),
    		"add_new_item" => esc_html__( "Add New Team", "custom-post-type-ui" ),
    		"edit_item" => esc_html__( "Edit Team", "custom-post-type-ui" ),
    		"new_item" => esc_html__( "New Team", "custom-post-type-ui" ),
    		"view_item" => esc_html__( "View Team", "custom-post-type-ui" ),
    		"view_items" => esc_html__( "View Teams", "custom-post-type-ui" ),
    		"search_items" => esc_html__( "Search Teams", "custom-post-type-ui" ),
    		"not_found" => esc_html__( "No Teams Found", "custom-post-type-ui" ),
    	];
    
    	$args = [
    		"label" => esc_html__( "Teams", "custom-post-type-ui" ),
    		"labels" => $labels,
    		"description" => "This is the post type for each team",
    		"public" => true,
    		"publicly_queryable" => true,
    		"show_ui" => true,
    		"show_in_rest" => true,
    		"rest_base" => "",
    		"rest_controller_class" => "WP_REST_Posts_Controller",
    		"rest_namespace" => "wp/v2",
    		"has_archive" => true,
    		"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,
    		"can_export" => false,
    		"rewrite" => [ "slug" => "team", "with_front" => true ],
    		"query_var" => true,
    		"supports" => [ "title", "editor", "thumbnail", "excerpt", "custom-fields", "revisions", "author" ],
    		"taxonomies" => [ "category", "layout_tag" ],
    		"show_in_graphql" => false,
    	];
    
    	register_post_type( "team", $args );
    }
    
    add_action( 'init', 'cptui_register_my_cpts' );
    
    
    
    
    
    function cptui_register_my_cpts_team() {
    
    	/**
    	 * Post Type: Teams.
    	 */
    
    	$labels = [
    		"name" => esc_html__( "Teams", "custom-post-type-ui" ),
    		"singular_name" => esc_html__( "Team", "custom-post-type-ui" ),
    		"menu_name" => esc_html__( "BU Teams", "custom-post-type-ui" ),
    		"all_items" => esc_html__( "All Teams", "custom-post-type-ui" ),
    		"add_new_item" => esc_html__( "Add New Team", "custom-post-type-ui" ),
    		"edit_item" => esc_html__( "Edit Team", "custom-post-type-ui" ),
    		"new_item" => esc_html__( "New Team", "custom-post-type-ui" ),
    		"view_item" => esc_html__( "View Team", "custom-post-type-ui" ),
    		"view_items" => esc_html__( "View Teams", "custom-post-type-ui" ),
    		"search_items" => esc_html__( "Search Teams", "custom-post-type-ui" ),
    		"not_found" => esc_html__( "No Teams Found", "custom-post-type-ui" ),
    	];
    
    	$args = [
    		"label" => esc_html__( "Teams", "custom-post-type-ui" ),
    		"labels" => $labels,
    		"description" => "This is the post type for each team",
    		"public" => true,
    		"publicly_queryable" => true,
    		"show_ui" => true,
    		"show_in_rest" => true,
    		"rest_base" => "",
    		"rest_controller_class" => "WP_REST_Posts_Controller",
    		"rest_namespace" => "wp/v2",
    		"has_archive" => true,
    		"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,
    		"can_export" => false,
    		"rewrite" => [ "slug" => "team", "with_front" => true ],
    		"query_var" => true,
    		"supports" => [ "title", "editor", "thumbnail", "excerpt", "custom-fields", "revisions", "author" ],
    		"taxonomies" => [ "category", "layout_tag" ],
    		"show_in_graphql" => false,
    	];
    
    	register_post_type( "team", $args );
    }
    
    add_action( 'init', 'cptui_register_my_cpts_team' );
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    The mention of Divi has me thinking you’re using something like https://www.elegantthemes.com/blog/divi-resources/how-to-use-a-blog-module-inside-a-category-and-or-archive-page-template and whatnot for display of things.

    That’s leading me to suggest reaching out to Divi support for what’s going on since it’s all their own code doing the querying and display, as opposed to what I’ll call “traditional” archive query and display that the code snippets above would be amending.

    Thread Starter pepperstreetuk

    (@pepperstreetuk)

    Hi I thought of this so I deactivated the theme and tried without DIVI using twenty twenty-two and the problem persists. I still can’t get the category results to display even without divi activated as the theme.

    Thread Starter pepperstreetuk

    (@pepperstreetuk)

    It strikes me the URL is wrong. My URL is https://bollingtonunited.co.uk/category/u7/

    When I have a different pre installed post type like projects the cat link is

    https://bollingtonunited.co.uk/project_category/test-cat/
    so shouldn’t my category link be

    https://bollingtonunited.co.uk/team_category/U7?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Can you try with perhaps one of the earlier Twenty* themes, i think TwentyTwentyTwo is pretty heavy on the Full Site Editing kick and may also not have archives fully set up out of box.

    Not sure how code savvy you are for other ideas and suggestions yet.

    Regarding your comment about links. project_category and team_category sound like custom taxonomies that have been added, and not the WP core, out of box category taxonomy that gets registered alongside post_tag Your team post type is registered with the WP core item, so /category/ urls would apply.

    Thread Starter pepperstreetuk

    (@pepperstreetuk)

    Nope nothing in 2020 either. I feel like I being really dim. I don’t have custom taxonomies. I just set up a new custom post type (Teams) I added posts to this area of the site and assigned them to categories. U7,U8 etc. I used the existing category taxonomy which was default with a new custom post type. THere are posts in each category. The post itself displays fine, but when I click on the category name in the meta I just get the NOTHING FOUND message where there should be a list of 2 or 3 teams.

    Thread Starter pepperstreetuk

    (@pepperstreetuk)

    I feel like I’m being dim because this should just work right out the box yes?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Would you be willing to contact us privately over at https://pluginize.com/contact/ and provide the thread link, https://wordpress.org/support/topic/no-results-for-category-page-with-custom-post-type/, in your message so we know which support request the support ticket there is for?

    Thread Starter pepperstreetuk

    (@pepperstreetuk)

    Done thanks

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    @pepperstreetuk Forgive me for not being sure. Did this ever get resolved? or did it get left in temporarily limbo in our private correspondence?

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘No results for category page with custom post type’ is closed to new replies.