从…起Codex 此代码段可能对您的案例有用:
显示“my\\u custom\\u post\\u type”类型的帖子,按“age”排序,并进行筛选以仅显示年龄3和4的帖子(使用meta\\u查询)
$args = array(
\'post_type\' => \'my_custom_post_type\',
\'meta_key\' => \'age\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\',
\'meta_query\' => array(
array(
\'key\' => \'age\',
\'value\' => array( 3, 4 ),
\'compare\' => \'IN\',
),
),
);
$query = new WP_Query( $args );