我想在WP\\u查询中显示年龄在5到10岁之间的帖子。我怎样才能做到这一点?
$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 );
最合适的回答,由SO网友:Shibi 整理而成
您可以在meta_query
您还需要为数字设置类型。
例如
$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( 5, 10 ),
\'compare\' => \'BETWEEN\',
\'type\' => \'NUMERIC\'
)
));
$query = new WP_Query( $args );