How to sort multiple wordpress custom field values?

后端 未结 4 1338
被撕碎了的回忆
被撕碎了的回忆 2021-02-06 12:47

Display posts with \'Product\' type ordered by \'Price\' custom field:

$query = new WP_Query( 
                      array ( \'post_type\' => \'product\', 
          


        
4条回答
  •  半阙折子戏
    2021-02-06 12:59

    You don't need any filter or hooks to sort multiple custom fields, if your one of custom field is meta_key and other one is normal column of table, than use these parameters/arguments in your query.

    'meta_key' => 'KEY_NAME',
    'orderby' => 'meta_value_num SECOND_COLUMN_NAME',
    'order' => 'ASC' or 'order' => 'DESC'
    

    Here the order of meta_value_num and SECOND_COLUMN_NAME matter, you may see different-2 result based on the order.

提交回复
热议问题