I have a custom post type query:
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'paged' => $paged,
'post_type' => 'my_custom_post_type',
'orderby' => 'meta_key',
// Here I am filtering posts further
'meta_query'=> array(
array(
'key' => '_assignment_type',
'value' => 'sales_assignment',
'compare' => 'LIKE',
),
),
// This is the part that isn't working at all:
'meta_key' => '_homepage_publish_date',
'meta_type' => 'datetime',
'order' => 'DESC',
'posts_per_page' => 30,
);
query_posts($args);
The values on _homepage_publish_date are like this: 2019-06-05 18:29:32.000
Whenever I try to get this order to work, the query returns the posts in the order where the posts were created.
What could be going wrong here?
I have a custom post type query:
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'paged' => $paged,
'post_type' => 'my_custom_post_type',
'orderby' => 'meta_key',
// Here I am filtering posts further
'meta_query'=> array(
array(
'key' => '_assignment_type',
'value' => 'sales_assignment',
'compare' => 'LIKE',
),
),
// This is the part that isn't working at all:
'meta_key' => '_homepage_publish_date',
'meta_type' => 'datetime',
'order' => 'DESC',
'posts_per_page' => 30,
);
query_posts($args);
The values on _homepage_publish_date are like this: 2019-06-05 18:29:32.000
Whenever I try to get this order to work, the query returns the posts in the order where the posts were created.
What could be going wrong here?
Share Improve this question asked Jun 20, 2019 at 17:03 JussiJussi 12 bronze badges1 Answer
Reset to default 0Well, the answer was staring right at my tired face. After hours of hairpulling, I noticed I had used:
'orderby' => 'meta_key'
I changed it to:
'orderby' => 'meta_value'
fixed things right up... -_-'