0
votes

I have to return all posts from custom post type, orderby 'start_date' from 'ACF field'.

I have posts with date and another posts with no date. When i add 'orderby' => 'meta_value_num' only my posts with start date are returned.

Here is my code :

$args_infos = array(
    'numberposts' => 9999999999999999,
    'post_type' => 'custom_post',
    'meta_key' => 'start_date',    //ACF field name
    'orderby' => 'meta_value_num',
    'order' => 'DESC',
    'post_status' => 'publish'
);

If I delete

    'meta_key' => 'field_name',
    'orderby' => 'meta_value_num',

All my posts are returned, but they are not ordered by 'start date'

Any idea ?

Thanks.

1

1 Answers

0
votes

Try :

$args_infos = array(
    'numberposts' => 9999999999999999,
    'post_type' => 'custom_post',
    'meta_key' => 'start_date',    //ACF field name
    'meta_type' => 'DATE',
    'orderby' => 'meta_value',
    'order' => 'DESC',
    'post_status' => 'publish'
);