I am using a URL rewrite to put the user's display name in the URL to display a user profile. This part all works fine and the proper value is passed through the query_vars and I can get the correct user.
Since this is for a plugin, some plugin users may want to use the user's first/last name instead of the display name. I've set up an opportunity for them to do that where the first/last name is separated by an underscore(_).
To retrieve the user when the URL rewrite is passing the query_var "display_name", I am using a meta query in
// Get the custom query_var value. $query_var = get_query_var( 'display_name' ); /** * When the display_name query_var is first name/last name, * (for example "john_smith"), split the value by unscore * to get the individual first and last name values. */ $pieces = explode( '_', $query_var ); // User meta query to get the user ID by first_name/last_name. $user = reset( get_users( array( 'meta_query' => array( 'relation' => 'AND', array( 'key'=>'first_name', 'value' => $pieces, 'compare' => '=' ), array( 'key' => 'last_name', 'value' => $pieces, 'compare' => '=' ) ), 'number' => 1, 'count_total' => false ) ) );
The meta query works fine and the correct user ID is returned, but I get a PHP notice as follows:
Notice: Only variables should be passed by reference
The line indicated is the meta query line
$user = reset( get_users( array(
Any thoughts on what is wrong and is throwing the PHP notice? Any ideas on a better query to get the user ID by first name/last name meta keys?