Rahajason
Rahajason

Reputation: 23

ACF compare dates from wordpress query

I have an ACF custom field with text as type but it stores date (string format), I have to search all custom post type between two dates and I don't know how to handle this.

$query = array(
    'key' => 'registration_date',
    'value' => array($startDate, $endDate),
    'compare' => 'BETWEEN',
    'type' => 'date'
);

Is not working because custom field value is a string format and comparison is not possible. How can i search post type between $startDate and $endDate then?

Thanks for your help

Upvotes: 0

Views: 1379

Answers (1)

Iteration
Iteration

Reputation: 683

I noticed that date comparaison only works with format YYYYMMDD, if you use something else like "DD.MM.YYYY" this will not work.

Your options are : 1. storing YYYYMMDD 2. using custom mysql queries.

Upvotes: 1

Related Questions