Make the search engine only show products as results –

Hosting Mautic QuickStart -50% with support in Spanish
24 hours and free training

Send up to 1,000,000 emails/year. Mautic Support in Spanish 24 hours, 365 days

The situation may arise that we have our website structured and later when adding the store section through woocommerce the search results take the term that has been placed globally, however what we want is that it only shows how results products associated with the term searched.

We can achieve this by means of a code snippet which we are going to add as follows.

By editing the functions.php file that is located in our hosting account within our cPanel/WePanel in the path File Manager -> public_html -> wp-content -> Themes -> Your_Theme (it is recommended that it be in a to avoid losing settings after an update in the main theme).

in cpanel

on WePanel

The code in question that we are going to add is the following:

// Show only products in searches add_filter(‘pre_get_posts’,’lw_search_filter_pages’); function lw_search_filter_pages($query) { // Frontend search only if ( ! is_admin() && $query->is_search() ) { $query->set(‘post_type’, ‘product’); $query->set( ‘wc_query’, ‘product_query’ ); } return $query; }

In this way, any search will only return products from the store as results.

Help us improve our content by sharing your opinion

WordPress and Woocommerce support team at .

See also  Microthemer, the WordPress plugin to change CSS on your website
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x