If you’re trying to get the last user created with the username format usuario*
, I’d recommend using get_users()
instead of writing a SQL query.
$args = array(
"search" => "usuario*", // Search string
"search_columns" => array( "user_login" ), // Field(s) to search
"order" => "DESC", // Search order
"orderby" => "user_registered", // Order by this
"number" => 1, // Get only this many users
);
$user_objects = get_users( $args );
// Ensure we've got results
if ( ! empty( $user_objects ) ) {
// Pull the 1st array element, which will be a WP_User object,
// and use the get() method to extract the username to a variable
$most_recent_usuario = $user_objects[0]->get( 'login_name' );
}
echo "<p>O último usuário é {$most_recent_usuario}</p>";
References
get_users()
WP_User_Query::prepare_query()
for the$args
detailsWP_User::get()
to extract theuser_login
from theWP_User
object