Created
March 5, 2019 18:18
-
-
Save FreshLondon/3b7213ea20b2daa21b3ee14de383e1fa to your computer and use it in GitHub Desktop.
Strips posts from search queries if ACF meta value post_is_hidden is active
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
<? | |
/** | |
* Strips posts from search queries if ACF meta value post_is_hidden is active. | |
* | |
* @author AM.HIGH | |
* @version 1.0.0 | |
* @since 1.0.0 | |
*/ | |
function dontSearchTheHidden($query) { | |
if (!$query->is_search()): | |
return; | |
endif; | |
$query->set('meta_query', array( | |
'relation' => 'OR', | |
array( | |
'key' => 'post_is_hidden', | |
'compare' => 'NOT EXISTS', | |
), | |
array( | |
'key' => 'post_is_hidden', | |
'value' => '0', | |
'compare' => '=', | |
), | |
)); | |
$query->set('post_type',array('post','page','property')); | |
} | |
add_action('pre_get_posts', 'dontSearchTheHidden'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment