Комментарии:
Thank for sharing this code.
I am using Elementor and search widget from Crocoblocks, and this code not working for me.
So i ask AI to create a new code for me, and it works just fine now. Thank u again.
function modify_wp_search_query( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'post', 'product' ) );
}
return $query;
}
add_filter( 'pre_get_posts', 'modify_wp_search_query' );
i love you men :)
ОтветитьRestricting WordPress Search to Titles Only for Woocommerce products titles
ОтветитьThanks :)
ОтветитьWhat if I only have posts added by the plugins CPT UI and Individual Fields? There are not showing in the search results.
Ответитьadded this code but now search results shows nothing found for any keyword
ОтветитьAmazing i was trying to solve this problem a couple of times and it works. Thanks!
ОтветитьHow can I Get Post by tags Or categories in search results.. 😔
Ответитьthank you so much
ОтветитьGracias te amo
ОтветитьThank you so much! It totally worked on my hello theme child.... You saved my life!
Ответитьthanks
Ответитьit works for me, thank you so much....
ОтветитьThanks mate! i was confident enough to use it on my parent theme and it worked!
Ответитьthanks .
ОтветитьHi Tony, I just tried to make your tip work for me. I am using WP 5.4.2 with the last version of OceanWP. I created a child theme and pasted the code at the end of functions.php, like you explained ... but it doesn't work :(
I get some part of the source code appear on top of the page (above the main menu) even if I don't trigger the search tool.
Great tip, But is this only for the Generate Press Theme? I tried it on Astra Pro Child theme but it did not seem to work.
ОтветитьHi, thanks for sharing this! one question. Is this still working for other themes? (I'm using Astra)
Ответить