- This topic has 10 replies, 3 voices, and was last updated 2 years, 11 months ago by
Fernando.
-
AuthorPosts
-
April 4, 2023 at 7:06 am #2596343
Scott
Dunno if this is a theme issue or a WP issue. But the ONLY search that works is the Woocommerce Product Search block and ONLY returns products. No other search block returns anything at all and just leads to a 404 page (which ironically has a search feature that also returns nothing). The navigation search thing also returns nothing.
/wp-content/themes/generatepress/assets/js/menu.min.js
/wp-content/themes/generatepress/assets/js/navigation-search.min.js
/wp-content/gp-premium/menu-plus/functions/js/offside.min.jshave all been excluded from WP-Rocket optimizations.
So I can search products … but Pages & Posts are not searched.
April 4, 2023 at 9:30 am #2596686Ying
StaffCustomer Supporthi there,
I just tested the search2 link you attached, and it works normally.
Have you tried testing it on another device?
Let me know!
April 4, 2023 at 10:17 am #2596751Scott
No I haven’t but I will and report back.
April 4, 2023 at 10:19 am #2596755Scott
Doesn’t work on a different device or different web connection.
April 4, 2023 at 10:35 am #2596781Ying
StaffCustomer SupportCan you disable all plugins except Woo and GP Premium?
If you are using a child theme, can you switch to the parent theme?
Let me know how it goes.
April 4, 2023 at 6:26 pm #2597210Scott
I found the issue. It’s this code snippet used to hide a product category from search results.
/* Remove Product Category from Search */ function remove_cat_from_search ( $q ) { if (!is_admin() && $q->is_main_query() && $q->is_search()) { $q->set( 'post_type', array( 'product' ) ); $tax_query = (array) $q->get( 'tax_query' ); $tax_query[] = array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'castlerockrehab','medicalsolutions' ), //no t-shirts in search 'operator' => 'NOT IN' ); $q->set( 'tax_query', $tax_query ); } } add_action( 'pre_get_posts', 'remove_cat_from_search' );which really sucks as I need this functionality 😔
April 4, 2023 at 6:50 pm #2597222Fernando Customer Support
Hi Scott,
To clarify, do you also want Posts to appear aside from Products when searching?
April 4, 2023 at 8:14 pm #2597278Scott
Ideally posts, pages, and products is what I’d prefer.
April 4, 2023 at 8:37 pm #2597290Fernando Customer Support
Can you try replacing the code you have with this?:
add_action( 'pre_get_posts', function( $query ) { if( ! is_admin() && is_search() && $query->is_main_query() ) { $query->set( 'post_type', array( 'page', 'post', 'product' ) ); $tax_query = (array) $query->get( 'tax_query' ); $tax_query[] = array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'castlerockrehab','medicalsolutions' ), //no t-shirts in search 'operator' => 'NOT IN' ); $query->set( 'tax_query', $tax_query ); } } );April 4, 2023 at 8:56 pm #2597316Scott
Like a charm. This isxwhy you guys and gals are the bestest!
April 4, 2023 at 9:09 pm #2597325Fernando Customer Support
You’re welcome, Scott!
-
AuthorPosts
- You must be logged in to reply to this topic.