-
Hi –
I have a question to the built in search modal.
How much do it search in – is it only WP page and post content? -
Alvind
Hi there,
By default, the built-in search only returns results from posts and pages. However, this can be changed — let us know what other content types (like products, or custom post types) you’d like to include in the search results.
-
OK, thanks for the answer.
Would it be possible to include Pages, Elements, Woocommerce products etc. and ACF?
-
Alvind
For WooCommerce products, I think they’re usually included in search results by default also. You can use this snippet to include other post types as well:
function include_custom_post_types_in_search($query) { if ($query->is_search && !is_admin()) { $query->set('post_type', array('post', 'page', 'your_custom_type')); } return $query; } add_filter('pre_get_posts', 'include_custom_post_types_in_search');Just replace
your_custom_typewith your actual custom post type slug.Curious though — what’s the reason you want to include Elements in the search results?
-
Thanks Alvind 🙂
I have a number of ACF templates for single posts and related posts, which are made in elements. I would like to be able to search all the posts that are generated via ACF…
-
I would like to be able to search all the posts that are generated via ACF…
I’m not sure what this means… posts are posts, are they not the post post type?
-
Yes, I can see that I haven’t expressed myself clearly.
What I want is to search in ACF fields. How do I extend the search to these fields as well? -
Alvind
Do you mean the values of ACF custom fields assigned to a post types?
If so, unfortunately I don’t think that’s possible.
-
OK, thanks for your time 🙂
-
Alvind
No problem 🙂
- You must be logged in to reply to this topic.