Home › Forums › ACF PRO › Exclude Posts by Date › Reply To: Exclude Posts by Date
I’m a little surprised that works at all because you can’t nest post__not_in inside of meta_query.
Do the standard “Posts” also have the date field? I’m assuming that this is not the case. If it is, then you’re query will not return any “posts” because that meta value is not set.
What you need to do is a query on your events to get the list of posts that you don’t want to include
$today = date('Ymd');
$args = array(
'post_type' => 'events',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'event_date',
'value' => $today,
'compare' => '<'
)
)
);
$old_events = new WP_Query($args);
$post__not_in = array();
if ($old_events->have_posts()) {
$post__not_in = wp_list_pluck($old_events->posts, 'ID');
}
now you can use what you code from the above for post__no_in
query_posts(array(
'post_type' => array('post','events'),
'showposts' => 20,
'post__not_in' => $post__not_in,
));
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.