Skip to content

Instantly share code, notes, and snippets.

@rianrietveld
Created December 15, 2012 09:14
Show Gist options
  • Save rianrietveld/4292303 to your computer and use it in GitHub Desktop.
Save rianrietveld/4292303 to your computer and use it in GitHub Desktop.
Exclude by missing meta value in WordPress query is not logged in using the Members plugin
add_filter( 'pre_get_posts', 'rrwd_filter_posts' );
function rrwd_filter_posts( $query ) {
if( !is_user_logged_in() ) {
$meta_query = array(
array(
'key' => '_members_access_role',
'compare' => 'NOT EXISTS'
)
);
$query->set( 'meta_query', $meta_query );
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment