Hi there,
I’m having a problem with sorting my posts by the value of the datepicker field. My custom date is saved in the yymmdd format.
This is my working query to display my posts and sort them by the custom date:
$wp_query = new WP_Query( array(
'post_type' => 'project',
'meta_key' => 'project_date',
'meta_query' => array(
'key' => 'project_date',
'type' => 'date'
),
'orderby' => 'meta_value_num',
'order' => 'DESC',
'paged' => $paged
));
get_template_part('templates/loop', 'project');
So far so good. Since the datepicker only saves a date and not a time, it can happen that 2 posts have the same date/value.
Let’s say I have 9 pages with on every page 10 posts;
If 2 posts have the same date but are both on page 4 for example, there is still no problem and both posts are displayed correctly.
However, if one of them happens to be the 10th post on page 4, and the other one the 1st on page 5, the 10th post on page 4 is being displayed as the 1st post on page 5? Very strange…
First I thought it was a caching problem, so I turned off my W3 Total Cache plugin completely, but that didn’t fix it.
So, is this a bug? And can I somehow add a random time value to the meta_value_num so they never can have the same value?
Thanks!