Home / functions.php / Check for post type within loop using get_post_type
  • Check for post type within loop using get_post_type

    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.

    wordpress snippet : PHP

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

    ( WordPress codex functions, hooks, in this snippet. )

    get_post, get_post_type,

Build a better with wpsnipp.com

Weekly snippets, themes, deals coupons roundup.

x No Thanks