T
T
Tarrissarh2018-02-06 16:15:23
MySQL
Tarrissarh, 2018-02-06 16:15:23

What's wrong with Wordpress/MySQL sorting?

There is a Wordpress database. The postmeta table has date (date, format YYYYmmdd) and title (name) metadata, these fields are sorted on the site. Basically, these fields are created/filled using the api and acf(update_field, for example) plugin functions, but you can also create them manually. Problem of the following character:
For example, we created 100 entries using api, and then made 10 entries manually.
When sorting in descending order (DESC), there are, as it were, 2 sorts for api and manual, i.e. in the beginning all dates or name go in descending order, which are created by hand, and then in descending order for api. and the sorting turns out to be something like this (an example for a date):
5a79a93cf3f9a639750324.png
For the name, the situation is similar.
Such sorting is not given by Wordpress, but by MySQL in its purest form, so I can’t understand what’s wrong.
Maybe someone faced a similar problem?

MySQL query
SELECT pm.meta_value FROM postmeta pm
WHERE pm.meta_key = 'name' # or date
ORDER BY pm.meta_value DESC
# Если для даты еще помогает ORDER BY pm.meta_value+0 DESC, то вот для названия...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2018-02-06
@Tarrissarh

Notice the different formatting. You obviously write different data, especially check for whitespace characters.
Do it And on the ASCII plate compare what you have extra at the beginning

B
Boris Korobkov, 2018-02-06
@BorisKorobkov

(date, YYYYmmdd format)

Not true. The date format is YYYY-mm-dd. And you do not understand what (string?).
Specify the exact table structure and SQL with sorting.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question