这种元查询WP_Query()
或get_posts()
:
\'meta_query\' => [
[
\'key\' => \'score\',
\'value\' => 50,
\'type\' => \'numeric\',
\'compare\' => \'>=\',
],
],
将生成以下SQL
WHERE
零件:
wp_postmeta.meta_key = \'score\' AND CAST(wp_postmeta.meta_value AS SIGNED) >= \'50\'
这种排序:
\'orderby\' => [
\'meta_value_num\' => \'DESC\',
\'title\' => \'ASC\'
],
将生成:
ORDER BY wp_postmeta.meta_value+0 DESC, wp_posts.post_title ASC
如果我们使用语法
defined here, 元查询数组索引为
score_clause
, 然后
\'orderby\' => [
\'score_clause\' => \'DESC\',
\'title\' => \'ASC\'
],
将生成:
ORDER BY CAST(wp_postmeta.meta_value AS SIGNED) DESC, wp_posts.post_title ASC