我问了一个问题,应该在哪里按字段外部链接排序,然后按价格字段排序。问题似乎是有些帖子有多个类别,似乎无法理解为什么它不按外部链接恶魔的顺序排序,然后按价格字段排序。
$query = new WP_Query( array(
\'post_type\' => post,
\'posts_per_page\' => -1,
\'meta_query\' => array(
\'relation\' => \'AND\',
\'price_clause\' => array(
\'key\' => \'price\',
\'compare\' => \'EXISTS\'
),
\'external_clause\' => array(
\'key\' => \'external_link\',
\'compare\' => \'EXISTS\'
)
),
\'orderby\' => array(
\'external_clause\' => \'DESC\',
\'price_clause\' => \'DESC\',
),
\'tax_query\' => array(array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => $category,
),)
) );
SO网友:Mark Anthony
我设法解决了此问题。问题类型=>“numeric”
$query = new WP_Query( array(
\'post_type\' => post,
\'posts_per_page\' => -1,
\'category_name\' => $category,
\'meta_query\' => array(
\'relation\' => \'AND\',
\'price_clause\' => array(
\'key\' => \'price\',
\'type\' => \'numeric\',
\'compare\' => \'EXISTS\'
),
\'external_clause\' => array(
\'key\' => \'external_link\',
\'compare\' => \'EXISTS\'
)
),
\'orderby\' => array(
\'external_clause\' => \'DESC\',
\'price_clause\' => \'DESC\',
),
) );