我是WordPress的新手。
当用户在浏览器URL中键入自己的名字时,我想在不登录WordPress的情况下获取前端的用户详细信息(Like example.com/{user-name})
然后按enter键,用户重定向一个新页面,如example.com/{user-name} 或example.com/user/{user-name}
任何人,请帮助我如何完成这项任务。
提前感谢
我是WordPress的新手。
当用户在浏览器URL中键入自己的名字时,我想在不登录WordPress的情况下获取前端的用户详细信息(Like example.com/{user-name})
然后按enter键,用户重定向一个新页面,如example.com/{user-name} 或example.com/user/{user-name}
任何人,请帮助我如何完成这项任务。
提前感谢
“用户”在WordPress中基本上是“作者”,因此这些页面可以在example.com/author/{user-name}/
(带或不带尾随斜杠)而实际上,您需要的是更改URL重写的“author permalink base”。例如:
add_action( \'init\', \'set_custom_author_base\' );
function set_custom_author_base() {
global $wp_rewrite;
$wp_rewrite->author_base = \'user\';
}
然后,您可以添加(或修改)author.php
您的子主题目录中的模板,以输出您想要显示的用户信息(但当然不能像这样在公共URL中共享私有用户信息)当然,这是一个简单的示例,使用plugin like this 如果你想保持/author/
对于某些角色,但对于其他角色,将其更改。
我使用get\\u users从数据库中获取用户。我正在使用此代码:$args = array ( \'role\' => \'Colaborador\', \'role__not_in\' =>[ \'subscriber\', \'Administrator\'], \'orderby\' => \'rand\' ); $user