custom post types - How to do WP_Query with two meta fields with orderby clause

The goal is to first try to order by the custom meta field and if its not found then do order by the post date. Here is

The goal is to first try to order by the custom meta field and if its not found then do order by the post date. Here is the query I did so far, but its not working.

$args = array( 
    'post_type' => 'xyz',
    'posts_per_page' => 5,
  'meta_query' => array(
    'relation' => 'AND',
    'query_one' => array(
      'key' => 'custom_meta',
      'compare' => 'EXISTS', 
    ), 
    'query_two' => array(
    'key' => 'post_date',
    ),
  ),
  'orderby' => array( 
    'query_one' => 'DESC',
    'query_two' => 'DESC',
  ),
  );
  $the_query = new WP_Query( $args );

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

相关推荐

  • custom post types - How to do WP_Query with two meta fields with orderby clause

    The goal is to first try to order by the custom meta field and if its not found then do order by the post date. Here is

    9小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信