Check for post type within loop using get_post_type

Adding this snippet within the loop of your wordpress theme will let you conditionally check for a specific post type. Just change the post type ‘products’ or ‘people’ to the post type you would like.



if ( 'products' == get_post_type() ){
... code to run if products post type...
}elseif ( 'people' == get_post_type()){
... code to run if people post type...
... code to run if neither of above post types...

Leave a comment