Support

Account

Home Forums General Issues How would I go about sorting by datepicker month,day (ignoring year)

Helping

How would I go about sorting by datepicker month,day (ignoring year)

  • I want to order posts like this:

    2015-01-01
    2018-01-28
    2017-05-31
    2018-06-14
    2014-06-21

  • You cannot do this using just a date picker field because the year is part of the stored value and the year is the first part of the value.

    In order to do this you would need to have another field where the month was first, followed by the day and then the year. This would be a non standard way to store a “date”.

    What I would do is create an acf/save_post filter that took the ACF date field value and store that value in my non-standard format into another post meta field using standard WP meta/custom field functions. I would then use this new field in my WP_Query to allow ordering the posts by this field.

    I posted a basic example here that shows how to do this. This example is for a repeater field, but the same principle can be applied to any field when you need some custom way to use the values in queries. https://acfextras.com/dont-query-repeaters/

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How would I go about sorting by datepicker month,day (ignoring year)’ is closed to new replies.