是否有一种快速简便的方法从usermeta表中获取用户选项,其键以字符串开头?
例如相当于:
的东西SELECT meta_value FROM usermeta WHERE meta_key LIKE 'StartString%'
答案 0 :(得分:1)
您可以在元查询中使用比较,如此;
$user_query = new WP_User_Query(
array(
'key' => meta_key,
'value' => 'StartString%',
'compare' => 'LIKE',
)
);
答案 1 :(得分:0)
<?php
global $wpdb;
$search = $wpdb->esc_like( "w" );
$search = $search . '%';
$sql = "SELECT * FROM $wpdb->usermeta WHERE $wpdb->usermeta.meta_key LIKE %s";
$sql = $wpdb->prepare( $sql, $search, $search);
$matching = $wpdb->get_results( $sql );
echo "<pre>"; print_r($matching);
?>