Title: is_post_type() within the loop?
Last modified: August 19, 2016

---

# is_post_type() within the loop?

 *  Resolved [Anointed](https://wordpress.org/support/users/anointed/)
 * (@anointed)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/is_post_type-within-the-loop/)
 * I have a loop that shows an array of posts from multiple post_types.
 * I simply want a check to say ‘if_post_type == “photogallery” ( do stuff) else(
   continue)
 * This would allow me to style the photogallery posts within the loop different
   from the regular and other post_types inside the loop.
 * This function does not work, but I can’t find a replacement function that allows
   this logic.
 * Can someone point me in the right direction?
 * thank you

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [demetris (Demetris Kikizas)](https://wordpress.org/support/users/demetris/)
 * (@demetris)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/is_post_type-within-the-loop/#post-1801477)
 * What you you need is `is_singular()`:
 *     ```
       if (is_singular('photogallery')) {
           # Do some stuff.
       } else {
           # Do some other stuff.
       }
       ```
   
 *  [Andrew Nacin](https://wordpress.org/support/users/nacin/)
 * (@nacin)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/is_post_type-within-the-loop/#post-1801594)
 * If you’re inside the loop and want to know about a specific post, then you’ll
   want to look at get_post_type(). is_singular() refers to the loop as a whole.
 *  [demetris (Demetris Kikizas)](https://wordpress.org/support/users/demetris/)
 * (@demetris)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/is_post_type-within-the-loop/#post-1801596)
 * Ouch. Apologies for the misinformation. Andrew Nacin is correct.
 * So, the correct example would be:
 *     ```
       if (get_post_type() == 'photogallery') {
           # Do some stuff.
       } else {
           # Do some other stuff.
       }
       ```
   
 *  [betadog](https://wordpress.org/support/users/betadog/)
 * (@betadog)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/is_post_type-within-the-loop/#post-1801758)
 * Awesome. Just what I needed right now. Thank you Andrew, thank you demetris. 
   You guys rock!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘is_post_type() within the loop?’ is closed to new replies.

 * In: [Alpha/Beta/RC](https://wordpress.org/support/forum/alphabeta/)
 * 4 replies
 * 4 participants
 * Last reply from: [betadog](https://wordpress.org/support/users/betadog/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/is_post_type-within-the-loop/#post-1801758)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
