• Resolved katstr

    (@katstr)


    Hello, I’ve successfully created two different custom post types using your plugin. However, the custom post types are not included in search results and are also not showing when using a related posts plugin. They also don’t show on author archive pages.

    It seems to me as if the database is not populated with the content of the custom post types. I put ‘query_var’ to true and ‘exclude_from_search’ to false.

    Any ideas how I can fix this problem? Thanks!

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

    (@tw2113)

    The BenchPresser

    Can you visit CPTUI > Tools and paste me the blob of content on the right hand side? I can use that to review other settings or import into a local install to test what you’re seeing. Most specifically to the search results part.

    Regarding the author archive, last I knew, modifying the code shown at https://docs.pluginize.com/article/17-post-types-in-category-tag-archives to check for is_author() instead of is_category() or is_tag() does the trick.

    Regarding the related posts plugin, you may need to reach out to their developers/support team to handle that part.

    Thread Starter katstr

    (@katstr)

    Hi Michael,

    Thanks for your reply!

    I tried the first snippet from this side for the search results:
    https://docs.pluginize.com/article/23-post-type-posts-in-search-results

    and the snippet that you suggested from here:
    https://docs.pluginize.com/article/17-post-types-in-category-tag-archives
    making this adjustment: if ( is_author() && empty( $query->query_vars['suppress_filters'] ) ) {

    Unfortunately, none of the snippets had the desired effect. I don’t know why it isn’t working. Am I supposed to replace anything else in the snippets?

    Here the code from the CPTUI tools section:
    {“use-cases”:{“name”:”use-cases”,”label”:”Use Cases”,”singular_label”:”Use Case”,”description”:”infsoft Use Cases”,”public”:”true”,”publicly_queryable”:”true”,”show_ui”:”true”,”show_in_nav_menus”:”true”,”delete_with_user”:”false”,”show_in_rest”:”true”,”rest_base”:””,”rest_controller_class”:””,”has_archive”:”true”,”has_archive_string”:”\/resources\/use-cases\/”,”exclude_from_search”:”false”,”capability_type”:”post”,”hierarchical”:”false”,”rewrite”:”true”,”rewrite_slug”:””,”rewrite_withfront”:”false”,”query_var”:”true”,”query_var_slug”:””,”menu_position”:”6″,”show_in_menu”:”true”,”show_in_menu_string”:””,”menu_icon”:”dashicons-portfolio”,”supports”:[“title”,”editor”,”thumbnail”,”excerpt”,”trackbacks”,”custom-fields”,”comments”,”revisions”,”author”,”page-attributes”],”taxonomies”:[“usecase_tags_en”,”usecase_categories”],”labels”:{“menu_name”:”Use Cases”,”all_items”:”All Use Cases”,”add_new”:”Add new”,”add_new_item”:”Add new Use Case”,”edit_item”:”Edit Use Case”,”new_item”:”New Use Case”,”view_item”:”View Use Case”,”view_items”:”View Use Cases”,”search_items”:”Search Use Cases”,”not_found”:”No Use Cases found”,”not_found_in_trash”:”No Use Cases found in trash”,”parent”:”Parent Use Case:”,”featured_image”:”Featured image for this Use Case”,”set_featured_image”:”Set featured image for this Use Case”,”remove_featured_image”:”Remove featured image for this Use Case”,”use_featured_image”:”Use as featured image for this Use Case”,”archives”:”Use Case archives”,”insert_into_item”:”Insert into Use Case”,”uploaded_to_this_item”:”Upload to this Use Case”,”filter_items_list”:”Filter Use Cases list”,”items_list_navigation”:”Use Cases list navigation”,”items_list”:”Use Cases list”,”attributes”:”Use Cases attributes”,”name_admin_bar”:”Use Case”,”item_published”:”Use Case published”,”item_published_privately”:”Use Case published privately.”,”item_reverted_to_draft”:”Use Case reverted to draft.”,”item_scheduled”:”Use Case scheduled”,”item_updated”:”Use Case updated.”,”parent_item_colon”:”Parent Use Case:”},”custom_supports”:””},”press”:{“name”:”press”,”label”:”Press”,”singular_label”:”Press”,”description”:””,”public”:”true”,”publicly_queryable”:”true”,”show_ui”:”true”,”show_in_nav_menus”:”true”,”delete_with_user”:”false”,”show_in_rest”:”true”,”rest_base”:””,”rest_controller_class”:””,”has_archive”:”true”,”has_archive_string”:””,”exclude_from_search”:”false”,”capability_type”:”post”,”hierarchical”:”false”,”rewrite”:”true”,”rewrite_slug”:””,”rewrite_withfront”:”false”,”query_var”:”true”,”query_var_slug”:””,”menu_position”:”7″,”show_in_menu”:”true”,”show_in_menu_string”:””,”menu_icon”:”dashicons-book”,”supports”:[“title”,”editor”,”thumbnail”,”excerpt”,”trackbacks”,”custom-fields”,”comments”,”revisions”,”author”,”page-attributes”],”taxonomies”:[“press_categories”],”labels”:{“menu_name”:””,”all_items”:””,”add_new”:””,”add_new_item”:””,”edit_item”:””,”new_item”:””,”view_item”:””,”view_items”:””,”search_items”:””,”not_found”:””,”not_found_in_trash”:””,”parent_item_colon”:””,”featured_image”:””,”set_featured_image”:””,”remove_featured_image”:””,”use_featured_image”:””,”archives”:””,”insert_into_item”:””,”uploaded_to_this_item”:””,”filter_items_list”:””,”items_list_navigation”:””,”items_list”:””,”attributes”:””,”name_admin_bar”:””,”item_published”:””,”item_published_privately”:””,”item_reverted_to_draft”:””,”item_scheduled”:””,”item_updated”:””},”custom_supports”:””}}

    Thanks for your help!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Something unrelated must be going on, as when I imported that, created a post in each, they immediately showed up in search queries when I searched for them by post title.

    Where did you put the code snippets? I added this version below to my active theme’s functions.php file and they were added to my author archive as well.

    function katstr_cptui_add_post_types_to_archives( $query ) {
    	// We do not want unintended consequences.
    	if ( is_admin() || ! $query->is_main_query() ) {
    		return;
    	}
    
    	if ( is_author() && empty( $query->query_vars['suppress_filters'] ) ) {
    		$cptui_post_types = cptui_get_post_type_slugs();
    
    		$query->set(
    			'post_type',
    			array_merge(
    				array( 'post' ),
    				$cptui_post_types
    			)
    		);
    	}
    }
    add_filter( 'pre_get_posts', 'katstr_cptui_add_post_types_to_archives' );
    
    Thread Starter katstr

    (@katstr)

    I agree, it looks like the issue is unrelated to your plugin. I put the code snippets in the functions.php of my child theme. I don’t have to replace the “my-cptui”, right?

    Thread Starter katstr

    (@katstr)

    Update: It is resolved now, the problem was another third-party plugin (polylang). Thanks again for your help!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Welcome.

    “my-cptui” isn’t a required part, it is just our way to try and ensure a unique function name to avoid fatal errors.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom post types not showing in search results and related posts’ is closed to new replies.