Created
December 23, 2020 19:01
-
-
Save jchristopher/4158f12854f3fc3bdd7c3daef902336e to your computer and use it in GitHub Desktop.
Tell SearchWP to ignore any post(s) with a specified meta key value
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 | |
// Tell SearchWP to exclude any posts with a my_meta_key | |
// value of 'meta value 1', 'meta value 2', or 'meta value 3'. | |
add_filter( 'searchwp\post__not_in', function( $ids ) { | |
return array_unique( array_merge( $ids, get_posts( [ | |
'fields' => 'ids', | |
'nopaging' => true, | |
'post_type' => 'any', | |
'meta_query' => [ [ | |
'key' => 'my_meta_key', | |
'value' => [ 'meta value 1', 'meta value 2', 'meta value 3', ], | |
'compare' => 'IN', | |
], ], | |
] ) ) ); | |
}, 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment