How we can get the author ID by its Name

get_user_by will get you the user data by ‘id’, ‘slug’, ’email’, or ‘login’.

‘slug’ is the user_nicename.

$user = get_user_by('slug','nicename');

However, I am not sure what you mean by ‘name’. There are other plausible ‘name’ fields, not all of them required. There is the display_name for example.

To search fields like user_nicename you will need to create a new WP_User_Query.

$args= array(
  'search' => 'Display Name',
);
$user = new WP_User_Query($args);

The default columns searched appear to be based on the type of data in the search field but you can restrict to particular fields by using the search_fields parameter.

$args= array(
  'search' => 'Display Name', // or login or nicename in this example
  'search_fields' => array('user_login','user_nicename','display_name')
);
$user = new WP_User_Query($args);

Leave a Comment