Created
September 15, 2024 13:04
-
-
Save atomjoy/1f25bc842a12872822ae32e455dcb115 to your computer and use it in GitHub Desktop.
Search posts only fliter
This file contains hidden or 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 | |
// Search only in posts with wordpress ?s= | |
function search_filter($query) { | |
if ($query->is_search) { | |
$query->set('post_type', 'post'); | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts','search_filter'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment