如果您试图获取使用用户名格式创建的最后一个用户usuario*
, 我建议使用get_users()
而不是编写SQL查询。
$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>";
参考文献
get_users()
WP_User_Query::prepare_query()
对于$args
详细信息WP_User::get()
提取user_login
从WP_User
对象