我使用以下方法从循环外部获取Wordpress的作者网址:
<?php
get_author_posts_url( $author_id, $author_nicename );
?>
通过以这种格式提供作者网址可以正常工作 -
mysitename.com/author/john-james
但是,启用Buddypress时,此相同的网址将更改为
mysitename.com/members/john-james
有没有办法防止这种情况发生?
答案 0 :(得分:1)
get_author_posts_url()
调用$wp_rewrite->get_author_permastruct()
默认返回:
$this->author_structure = $this->front . $this->author_base . '/%author%';
WP_Rewrite
类有此过滤器,可让您更改值:
apply_filters( 'author_rewrite_rules', array $author_rewrite )
答案 1 :(得分:0)
我最终必须使用此代码 - <?php echo get_site_url(); ?>/author/<?php echo($user_name); ?>
其中$user_name = $user_info->user_nicename;
这也让我 - mysitename.com/author/john-james
可能还有其他方法,但这允许我将两个URL一起用于不同目的,一个用于检查作者的个人资料(通过buddypress),另一个用于查看所有作者的文章。