I would like to use a meta_key
to store multiple values in that key. Thereafter, I would like to filter away posts that do not contain a specific value in the key. In other words, just show posts that do not contain a specific value. This, however, does not seem to be possible. I am writing this question here to see if anyone has come to the same conclusion or if I am just missing something.
Here is the code I have used:
// The values in key "_no_interest" are: 1,2,3
add_action( 'pre_get_posts', 'custom_pre_query' );
function custom_pre_query( $query ) {
if( $query->is_main_query() && !is_admin() && $query->is_post_type_archive( 'my_custom_post_type' ) ) {
$meta_query = array(
array(
'key' => '_no_interest',
'value' => '3',
'compare' => 'NOT IN'
)
);
$query->set( 'meta_query', $meta_query );
$query->set( 'posts_per_page', -1 );
$query->set( 'post_status', 'publish' );
$query->set( 'orderby', 'date' );
}
}
This will not work and neither will it if I use the '!='
operator. However, if I set compare to be equal to 'IN'
or '='
, then it will work.
Can anybody confirm this or am I missing something here?