Home › Forums › General Issues › Custom year dropdown filter for CPT › Reply To: Custom year dropdown filter for CPT
Hi @kaolarsan,
Thanks for the post.
The easiest way to go about this would be to create a custom query using the get_posts() function and filter the posts using the values entered in the datepicker field.
Essentially, the code would look like so:
<?php
$today = date('Ymd');
$args = array (
'post_type' => 'post',
'meta_query' => array(
array(
'key' => 'start_date',
'compare' => '>=',
'value' => $today,
),
array(
'key' => 'end_date',
'compare' => '<=',
'value' => $today,
)
),
);
// get posts
$posts = get_posts($args);
?>
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.