【问题标题】:redirecting to author page in wordpress在 wordpress 中重定向到作者页面
【发布时间】:2017-03-20 05:11:45
【问题描述】:

我需要将来自某个网​​址“http://www.example.com/wp-includes/qp2qp-sktcho/”的访问者重定向到他们在 wordpress “http://www.example.com/author/username”中的作者页面,并且我在其中一个主题文件中使用此代码

if($_SERVER['HTTP_REFERER']){
  if($_SERVER['HTTP_REFERER'] == "http://www.example.com/wp-includes/qp2qp-sktcho/" && is_user_logged_in()){
       $targetUrl = get_author_posts_url($user->user_nicename );
       wp_redirect( $targetUrl );
add_action('pre_get_posts','wh_post_display_order_view');
       exit;
   }
} 

但不是重定向到“http://www.example.com/author/username” 它重定向到“http://www.example.com/author/

你知道代码有什么用吗? 谢谢

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    尝试将get_author_posts_url($user->user_nicename ); 替换为get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) );

    请检查转储函数输出

    var_dump();

    以确保它是否返回正确的 url。稍后,然后删除 var_dump();

    请同时查看https://codex.wordpress.org/Function_Reference/get_author_posts_url

    【讨论】:

      【解决方案2】:

      将您的 get_author_posts_url 更改为以下:

      get_author_posts_url( get_the_author_meta( 'ID' ) );
      

      更多详情请看这里:

      https://codex.wordpress.org/Function_Reference/get_author_posts_url

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-07-09
        • 2015-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-25
        • 1970-01-01
        相关资源
        最近更新 更多