Created
November 12, 2023 13:00
-
-
Save braddalton/2a4523a02e2ee398c7beb5089c0468a8 to your computer and use it in GitHub Desktop.
Exclude products from search results in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function exclude_products_from_search($query) { | |
if (is_admin() || !$query->is_main_query()) { | |
return; | |
} | |
if ($query->is_search) { | |
$query->set('post_type', array('post', 'page')); // Exclude products from search results | |
} | |
} | |
add_action('pre_get_posts', 'exclude_products_from_search'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment