Home › Forums › General Issues › How to sort by ACF field › Reply To: How to sort by ACF field
Hi,
you can do it like this:
$currentDate = date('Ymd');
$args = array(
'numberposts' => -1,
'meta_key' => 'date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'date',
'compare' => '>=',
'value' => $currentDate,
),
)
);
this would return all the posts where the “date” field is equal to the current date or later. (you would need to change the “date” on my code to your “event_date” field name and add other arguments you may want to have like “cat”=> ‘2’ the save format of your date field should be set to yymmdd
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.