I'm trying to add a feature to my loop.php to use with a custom post type. However, I don't want it displayed on all posts, just the ones that are the custom post type (let's say its called "review").

Is there a way to say if post type = review then show this new section, otherwise hide?

I tried using

<?php if( get_post_type() == 'reviews' ) 

but I don't know how to phrase the else statement to just do nothing and continue on normally.

Thank you!

3 Answers 3


Try the following:

if ( have_posts() )
    while( have_posts() )

        if ( 'reviews' === get_post_type( get_the_ID() )
            echo 'I am a post of the post type &rdquo;reviews&ldquo;';

            // We're done here, continue to next post

        // Do other stuff


In case you're not sure if you got that post type available, use the following plugin to check (below your admin user interfaces footer) what custom post types you got available.

/** Plugin Name: »kaiser« Get custom post type objects */
function wpsedebug_post_type_obj()
    if ( ! is_admin() )

    $pt = get_post_types(
             'public'   => true
            ,'_builtin' => false
    return print '<pre>'.var_export( $pt, true ).'</pre>';
add_action( 'shutdown', 'wpsedebug_post_type_obj' );
  • I tried that, it doesn't display anything if I add that section in. Basically, as soon as I add an if statement to that part of the loop, it blanks out the page.
    – hiiambo
    Commented Oct 29, 2012 at 14:52
  • @BoShubinsky First: White screen means that there's an error and you haven't turned debugging on (see Codex for more info on how to debug in WP). Second: Take a look at the plugin I added to see what your post type really looks like/is named.
    – kaiser
    Commented Oct 29, 2012 at 15:32

try http://codex.wordpress.org/Function_Reference/get_post_type use that to get your custom post type's value and to compare it

For instance:

<?php $myPostType = get_post_type( $post->ID ); 
 if($myPostType == 'Review'){
  //It's a review post type, whoo!
  • When I try adding that to the loop, it just makes everything blank. It's not displaying any posts at all.
    – hiiambo
    Commented Oct 29, 2012 at 14:44
  • First try <?php echo get_post_type( $post->ID ); ?> and see which value it gives you
    – Halaster
    Commented Oct 29, 2012 at 14:46

I figured it out. I had to format it like this:

<?php if( get_post_type() == 'reviews' ) { ?>
// stuff inside if statement
<?php } ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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