If you work with WordPress themes and Custom Post Types you will love the snippet below.
This is a conditional check for custom post types within The Loop:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php if ( 'review' == get_post_type() ) { /* Custom code for 'review' post type. */ } elseif ( 'restaurant' == get_post_type() ) { /* Custom code for the 'restaurant' post type. */ } ?> |
If you want to use the snippet outside the loop you just need to pass the post ID:
1 2 3 4 5 6 7 8 9 10 |
<?php if ( 'product' == get_post_type( 123 ) ) { /* Do something */ } ?> |
Learn more about the get_post_type function.