WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Well I made a plugin that uses template_redirect for the custom post type squeezepages and it works all fine and dandy, but I copied the exact same code, put it in a new plugin, activated it (with a few minor adjustments, for example I changed the custom post type to newpages and the template_redirect is taking the template from a different source) and suddenly it doesn't work?

I can have both plugins active at the same time, the squeeze pages work, the new pages don't. It puzzles me so much. I even disabled the squeeze pages plugin and it still doesn't work. I've tried all combinations (there's only a couple) and still nothing. It seems like it's not working for NO reason. I've been staring at the same code for 2 hours and I'm not able to figure it out.

Here's the code for my custom post types:

add_action( 'init', 'ifp_create_post_type' );
function ifp_create_post_type() {
register_post_type( 'newpages',
        'labels' => array(
            'name' => __( 'New Pages' ),
            'singular_name' => __( 'New Page' )
    'public' => true,
    'menu_position' => 5,
    'rewrite' => true,
    'rewrite' => array('slug' => 'newpage', 'with_front' => FALSE),
    'supports' => array('title', 'editor', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'thumbnail', 'author', 'page-attributes')

And my template_redirect:

function ifp_default_template() {
    if(get_post_type() == 'newpages') : global $wp_query, $post, $posts;
    include(PLUGINDIR . '/newpage/themes/default.php');
    exit; endif;
add_action('template_redirect', 'ifp_default_template');
share|improve this question

Not much code here... Let's break it down into things that can go wrong:

  1. Verify that ifp_default_template()is firing (for example earlier redirect could include another template and dies, never reaching it).

  2. Verify that get_post_type() returns expected value.

  3. Verify that include path is being generated correctly (I'd use plugins_url(), it's more robust than building path from strings).

share|improve this answer
Thanks for your help, I figured out that it is returning the post type as post and not newpages - why would it be doing that? – Jared Mar 7 '11 at 9:38
@Jared dump global $post and see what it holds. get_post_type() pretty much returns post_type field from it (with few sanity checks on top). – Rarst Mar 7 '11 at 9:52
It's still returning the post type as post after removing global $post;. Could it have to do with register_post_type? – Jared Mar 7 '11 at 9:55
get_post_type is for use inside the loop, according to the docs. – t31os Mar 7 '11 at 10:49
up vote 1 down vote accepted

I solved my own problem. I needed to put flush_rewrite_rules( false ); after my register_post_type function. The reason it wasn't working is because it was returning the page with a 404 error, so I figured out it was a permalinks problem and the code above solved it for me.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.