WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] template_redirect keeps redirecting (2 posts)

  1. Mads Phikamphon
    Member
    Posted 1 year ago #

    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

  2. Mads Phikamphon
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic