PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 17, 2022

[FIXED] Wordpress: WP_Query ordering anomaly

 February 17, 2022     advanced-custom-fields, wordpress     No comments   

Issue

I'm ordering a set of posts by an ACF date field using these arguments in WP_Query

'orderby' => 'meta_value',
'order' => 'ASC',
'meta_key'      => 'date', //ACF date field

Which seems to work, except it's throwing an anomaly.

This is an echo of the list of dates (stored as Ymd)

20211221
20220118
20220125
20220201
20220208
20220215
20220222
20220301
...
20221122
20221129
20221206
20221213
20221220
20220111

The last one, which should be second, is appearing last. (they are weekly dates starting 21st December 2021


Solution

Try to use meta_value_date instead of meta_value as orderby parameter.

see also https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters



Answered By - Johannes
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing