wp query – How to add a “base” filter for all posts visible to visitors on the site?
I’d like to filter all posts ever visible to my visitors by the posts’ custom meta (box) tag value.
I added a post meta box “access_required” and I want to check if the post’s access_required value is included in an array I’ve linked to the visitors’ session. I want to only render the posts with an empty “access_required” value, or with a value included in the visitor’s “access” array.
This is what I have so far:
$user_access = get_visitor_var('access'); // Custom function simply returning an array of strings
...
$available_posts = array(
'meta_query' => array(
array(
'key' => '_access_required_meta_key',
'value' => $user_access,
'compare' => 'IN',
)
)
);
My biggest problem is that I’m a WP/PHP noob, I come from a C#/Node.js background but had to get a WP plugin finished to link two sites together.
Would be great if someone could tell me how to properly add a “base” filter to wordpress, filtering out any post the visitor should not be able to see; preferably keeping pagination etc. working.
Thanks in advance for any answers!
Leave an answer