WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] template_redirect keeps redirecting

[Resolved] template_redirect keeps redirecting

  • Hi,

    I use template_redirect to redirect 404 requests to a custom template file (products.php):

    add_filter('template_redirect', 'mp_404_filter_override' );
    
    function mp_404_filter_override() {
        global $wp_query;
    if(<SOME BUSINESS LOGIC>)
    {
      status_header( 200 );
      $wp_query->is_404=false;
    
      include (TEMPLATEPATH . '/products.php');
      exit;
    }
    }

    No problems redirecting the users. They all end up on products.php as they should.

    The problem is that products.php keeps reloading since the template_redirect filter I have set up is checked again and again.

    Any ideas on how I can stop products.php from reloading?

    Thanks,
    Mads

Viewing 1 replies (of 1 total)
  • Found a solution: Make sure products.php is a WP template and not just some random test HTML.

    The code above works perfectly (without reloading) if the products.php is a WP template.

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] template_redirect keeps redirecting’ is closed to new replies.
Skip to toolbar