Tagged: x
-
AuthorPosts
-
January 10, 2017 at 8:07 am #1323890
TimParticipantHi,
Is there a simple solution to show only woocommerce products on the search results?
I have this piece of code:
add_filter( 'pre_get_posts', 'custom_search' ); function custom_search( $query ) { if ( $query->is_search ) { $query->set( 'post_type', array( 'product' ) ); } return $query; }Which is working fine, but it also affects the backend search results..maybe you have an idea of modifying this to apply only in the frontend?
Thanks..
Cheers
TimJanuary 10, 2017 at 8:42 am #1323932
ChristianModeratorHey Tim,
Regretfully, this is outside the scope of our support. Please try using a search plugin like SearchWP. There are also other third party plugins for WooCommerce that can do that. Or, you might want to contact our trusted partners who caters X setup and customization needs. Please see https://community.theme.co/custom-development/
Thank you for understanding.
January 10, 2017 at 9:42 am #1324029
TimParticipantHi Christian,
Is this a new policy? In other threads you help customers with this issue far more deeply (back in 2014 & 15) but none of these answers seems to work anymore..
January 10, 2017 at 10:28 am #1324109
ThaiModeratorHi There,
Please update your code to this:
add_filter( 'pre_get_posts', 'custom_search' ); function custom_search( $query ) { if ( $query->is_search && !is_admin() ) { $query->set( 'post_type', array( 'product' ) ); } return $query; }Hope it helps 🙂
January 19, 2017 at 5:18 am #1336489
TimParticipantHi Thai,
Works perfectly, thanks!
Have a great day..
Cheers
January 19, 2017 at 6:55 am #1336582
Paul RModeratorYou’re welcome! 🙂
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1323890 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
