最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论