最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to filter users by last_name?

programmeradmin1浏览0评论

How can I implement functions.php as a last name filter option? Note that a search for users on the Wordpress admin panel page - users.php is not possible to filter users by the last name, how can you include this filter? Does anyone share any snippets for this?

I tried this but it doesn't work.

//search usertable
$wp_user_query = new WP_User_Query(
  array(
    'search' => "*{$str}*",
    'search_columns' => array(
    'user_login',
    'user_nicename',
    'user_email',
  ),

) );
 $users = $wp_user_query->get_results();

//search usermeta
 $wp_user_query2 = new WP_User_Query(
  array(
    'meta_query' => array(
    'relation' => 'OR',
      array(
        'key' => 'first_name',
        'value' => $str,
        'compare' => 'LIKE'
      ),
    array(
        'key' => 'last_name',
        'value' => $str,
        'compare' => 'LIKE'
      )
    )
  )
 );

$users2 = $wp_user_query2->get_results();

$totalusers_dup = array_merge($users,$users2);

$totalusers = array_unique($totalusers_dup, SORT_REGULAR);

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论