wp query - Order by meta date with a thousanth of a second defaults to post order

I have a custom post type query:$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

Well, 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... -_-'

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745383560a4625341.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信