元价值观:
$args = array(
'meta_key' => 'featuredservice03',
'meta_value' => 'a:1:{i:0;s:3:"yes";}',
'orderby' => 'meta_value',
'order' => 'ASC'
);
循环:
$user_query = new WP_User_Query( $args );
foreach ( $user_query->results as $author ) {
//code goes here..
}
试图让循环只显示具有' featuredservices03'有"是"的价值子串。我是否必须序列化meta_value?
答案 0 :(得分:0)
例如,请考虑您的meta_value
1. a:1:{i:0;s:3:"yes";}
2. a:2:{i:0;s:3:"no";i:1;s:6:"yes ok";}
由于元值是序列化的,因此您必须在序列化字符串中搜索“值”。
$args = array(
'meta_query' => array(
array(
'key' => 'featuredservice03',
'value' => '%yes%', // search with value
'compare' => 'LIKE'
)
),
'orderby' => 'meta_value',
'order' => 'ASC'
);
结果:
a:1:{i:0;s:3:"yes";}
a:2:{i:0;s:3:"no";i:1;s:6:"yes ok";}
或者您可以创建要在元值
中搜索的“序列化值”$args = array(
'meta_query' => array(
array(
'key' => 'featuredservice03',
'value' => serialize( array( 'yes' ) ), // search with serialized array
'compare' => 'LIKE'
)
),
'orderby' => 'meta_value',
'order' => 'ASC'
);
结果:
a:1:{i:0;s:3:"yes";}