Support » Plugins » Using template_redirect to reset page ID

  • I’m working on a theme that utilizes several custom post types. At the top of each page, there’s navigation to switch between the “sections.”

    On the home page, there is an intro-blurb that’s defined as a Page, with a custom page template.

    Now, when someone goes to the home page, the default CPT archive gets pulled up just fine. When I click on another CPT archive, however, I lose that top blurb.

    I’ve successfully gotten template_redirect to load the custom page template but, shocking I know, it doesn’t load the content from the page set as front page.

    Any ideas on how I can get WP to load that automatically? I’m trying to avoid hard coding in a check, although that may be my only option.


    Kind of a pseudocode example of what I’m trying to accomplish

    //if CPT is set and we're not browsing a category
    if(!empty($section) && empty($category)): 
      global $wp_query;
      // tell WP what page to use in the loop
      $wp_query->set_query_var('page_ID', 4); 
      // load the right template
      include(get_stylesheet_directory() . '/templates/page-home.php');

  • The topic ‘Using template_redirect to reset page ID’ is closed to new replies.