Wordpress重定向问题

Wordpress重定向问题,wordpress,Wordpress,我目前将下面的代码添加到我的functions.php中,以便在用户访问我的网站时重定向他们。仅当“更新赛车记录”的值设置为“是”时,才会重定向用户 然而,我遇到了一个“重定向太多”的问题,因为Wordpress即使在用户到达最后一页后也会继续重定向用户。为了阻止这种情况,我添加了“is_page”条件,但这似乎不起作用。我仍然收到“重定向太多”错误 我错过了什么 add_action( 'init', 'my_redirect' ); function my_redirect(){

我目前将下面的代码添加到我的functions.php中,以便在用户访问我的网站时重定向他们。仅当“更新赛车记录”的值设置为“是”时,才会重定向用户

然而,我遇到了一个“重定向太多”的问题,因为Wordpress即使在用户到达最后一页后也会继续重定向用户。为了阻止这种情况,我添加了“is_page”条件,但这似乎不起作用。我仍然收到“重定向太多”错误

我错过了什么

add_action( 'init', 'my_redirect' );

function my_redirect(){

    global $wpdb;

    // if user is logged in
    if( is_user_logged_in() ) {

      // set vars
      $racer_id = find_racer_id();
      $update_racer_record = 'NO';

      // check to see if the user record has been updated in the last 6 months
      $update_racer_record = $wpdb->get_var("
                select 'YES'
                  from flx_racers
                 where racer_id = " . $racer_id . "
                   and ifnull(update_date, date_sub(now(), interval 7 month)) < date_sub(now(), interval 6 month);
      ");

      // if user record has not been updated in the last 6 months, redirect
      if ( $update_racer_record == 'YES' ) {

        // if we are not currently already in the personal info page, then redirect to it
        if ( !is_page( 'flx-racer-personal-info' ) ) {
          wp_redirect( site_url().'/flx-racer-personal-info/' ); exit;
        }

      }

    }

}
add_action('init','my_redirect');
函数my_redirect(){
全球$wpdb;
//如果用户已登录
如果(用户是否已登录){
//设置变量
$racer\u id=find\u racer\u id();
$update_racer_record='NO';
//检查用户记录在过去6个月内是否已更新
$update\u racer\u record=$wpdb->get\u var(“
选择“是”
来自flx_赛车手
其中racer_id=“.$racer_id.”
和ifnull(update_date,date_sub(现在(),间隔7个月))
我修复了它,现在它工作得很好!只需更改添加操作代码

由此:

add_action( 'init', 'my_redirect' );
为此:

add_action( 'template_redirect', 'my_redirect' );