1 回答
TA贡献1864条经验 获得超2个赞
当然,它不会显示任何结果,因为您没有拆分名字和姓氏。
$name = 'John Doe';
$parts = explode(" ", $name);
$first_name = $parts[0];
$last_name = (count($name) > 1) ? $name[count($name)-1]: $first_name;
$args = array(
'post_type' => 'customers',
'post_status' => array( 'publish', 'pending', 'draft' ),
'numberposts' => -1,
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => 'customer_first_name',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'customer_first_name',
'value' => $first_name,
'compare' => 'LIKE',
),
array(
'key' => 'customer_last_name',
'value' => $last_name,
'compare' => 'LIKE',
),
),
);
$customers = get_posts($args);
$num = count( $customers );
与国际名称一样,如果姓氏为空,则姓氏也将使用名字。
- 1 回答
- 0 关注
- 126 浏览
添加回答
举报