I
I
Ivan Koretsky2020-05-02 18:35:13
WordPress
Ivan Koretsky, 2020-05-02 18:35:13

How to make a query sorted by year of birth WP_Query?

Good day!
There is an arbitrary field "Date", where the date of birth of a person is selected.
5ead92696150f839176685.jpeg
It is necessary to make sure that posts are displayed on the archive page in ascending order of the year of birth, i.e. older ones at the beginning and younger ones at the end.

This example sorts by an arbitrary field of pure numeric value. And the date is displayed like this 06/21/2001, so it's not possible to sort in the same way

$query = new WP_Query( array(
    'post_type' => 'property',
    'meta_query' => array(
        array(
            'key' => 'price',
            'value' => 50000,
            'compare' => '<=',
            'type' => 'NUMERIC',
        ),
    ),
) );

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question