Answer the question
In order to leave comments, you need to log in
How to sort wordpress posts by custom field?
There is Wordpress.
In addition to the publication date, records have an arbitrary field with a date in the format 12/31/2015 (the date of the event described in the article).
It is necessary to sort the records by the date of an arbitrary field, and optionally, and not forever, but pressed the button - sorted, opened the category again - sorted by publication date.
I found an option to simply change the query to the database and add ORDER BY wpostmeta.meta_value DESC, but
1. it is necessary that such sorting be on request, and not permanently for all visitors
2. the date format 12/31/2015, as I understand it, will not allow ORDER BY to sort correctly , but the fields are already there and converting to a different format is not an option
. How to get out?
Answer the question
In order to leave comments, you need to log in
To sort by click, use ajax
Sorting by date from an arbitrary field depends on how you store this date, if in Unix format or something like this 20150108
You can use the standard API engine
$args = array(
'orderby' => array(
'meta_value_num',
),
'order' => 'ASC',
'meta_key' => '%ключ поля%'
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question