Created
October 4, 2023 16:17
-
-
Save SteveJonesDev/2b963a33fb6b8e2f89cc6004b1f35bf7 to your computer and use it in GitHub Desktop.
functions.php
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
<?php | |
function restrict_search_to_specific_post_type($query) { | |
// Check if query is a search, is on the frontend, and is on the 'product' post type archive | |
if ($query->is_search && !is_admin() && is_post_type_archive('product')) { | |
$query->set('post_type', 'product'); | |
} | |
return $query; | |
} | |
add_action('pre_get_posts', 'restrict_search_to_specific_post_type'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment