10up / ElasticPress

A fast and flexible search and query engine for WordPress.
https://elasticpress.io
GNU General Public License v2.0
1.24k stars 312 forks source link

Having a Custom Post Type show in Custom Search Results option #3879

Closed gwhitehead closed 4 months ago

gwhitehead commented 5 months ago

Describe your question

I have a CPT for Product Categories. When I go to the Custom Results section of ElasticPress, I try to set up a search term and then search for a title of one of the Product Categories that is set up. I am not able to see the category that is the exact term that I am looking for within the available pages?

Or is there a way to set up custom URL's as a landing page? For instance, I want to send to a #bookmarked location on a specific page within the website.

Code of Conduct

felipeelia commented 5 months ago

Hi @gwhitehead! ElasticPress will display all CPTs that are not excluded from search (see here and then here.

If you want, please share the code you are using to create that CPT, so we can try to reproduce it from our side.

gwhitehead commented 5 months ago

Here is the arguments part of the register post type for the CPT product:

$args = [ "label" => __( "Products", "custom-post-type-ui" ), "labels" => $labels, "description" => "", "public" => true, "publicly_queryable" => true, "show_ui" => true, "show_in_rest" => false, "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" => "product", "with_front" => true ], "query_var" => true, "supports" => [ "title", "editor", "thumbnail", "excerpt", "revisions", "page-attributes" ], "show_in_graphql" => false, ];

I had to manually run a wp elasticpress sync --post-type="product" to get it to finally show products that had been in the system for a few months. There are a lot of additional fields in the system so I usually have to run the sync via the wp-cli to get it to fire.

gwhitehead commented 5 months ago

And here is the product category post type:

$args = array( 'label' => __( 'Product Category', 'text_domain' ), 'description' => __( 'Product Category', 'text_domain' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'page-attributes' ), 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 40, 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'page', );

github-actions[bot] commented 5 months ago

It has been 3 days since more information was requested from you in this issue and we have not heard back. This issue is now marked as stale and will be closed in 3 days, but if you have more information to add then please comment and the issue will stay open.

gwhitehead commented 5 months ago

I have made sure to go through all of the functions code to ensure nothing is being marked as excluded. Also not being marked as excluded via a checkbox either. It wasn't until I told the search to manually search just that post type that it started to show up in search results.

github-actions[bot] commented 4 months ago

It has been 3 days since more information was requested from you in this issue and we have not heard back. This issue is now marked as stale and will be closed in 3 days, but if you have more information to add then please comment and the issue will stay open.

felipeelia commented 4 months ago

@gwhitehead I tried to reproduce the problem but I couldn't. If I use that code to create a post type and create an entry, it is displayed in search by default. As you've already figured out how to work around your specific problem, I'm going ahead and closing the issue.