Title: problem with post_type on custom post type in Loop
Last modified: August 19, 2016

---

# problem with post_type on custom post type in Loop

 *  Resolved [niceandripe](https://wordpress.org/support/users/niceandripe/)
 * (@niceandripe)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/problem-with-post_type-on-custom-post-type-in-loop/)
 * I have registered a custom post type of ‘directory’ and in my loop i have something
   like this:
 *     ```
       <?php if ( in_category( _x('gallery', 'gallery category slug') ) ) : ?>
   
           XXX - this is what i expect for gallery posts
   
       <?php elseif ( $post_type = 'directory' ) : ?>
   
       	YYY - this is what i expect for directory (custom) posts
   
       <?php else : ?>
   
       	ZZZ - this is what i expect for regular posts
   
       <?php endif;  ?>
       ```
   
 * however, even thou a regular post is not $post_type = ‘directory’ I’m getting
   YYY – this is what i expect for directory (custom) posts when I’m expecting ZZZ–
   this is what i expect for regular posts
 * help! (please)

Viewing 1 replies (of 1 total)

 *  Thread Starter [niceandripe](https://wordpress.org/support/users/niceandripe/)
 * (@niceandripe)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/problem-with-post_type-on-custom-post-type-in-loop/#post-1581997)
 * this was solved on trac
    [http://core.trac.wordpress.org/ticket/14304](http://core.trac.wordpress.org/ticket/14304)
 * >  Looks like you are always setting your $post_type = ‘directory’; To do a check
   > you would need to use == rather than =.
   > Check the code below, it should do the trick.
   >     ```
   >     <?php if ( in_category( _x('gallery', 'gallery category slug') ) ) : ?>
   > 
   >         XXX - this is what i expect for gallery posts
   > 
   >     <?php elseif ( $post_type == 'directory' ) : ?>
   > 
   >     	YYY - this is what i expect for directory (custom) posts
   > 
   >     <?php else : ?>
   > 
   >     	ZZZ - this is what i expect for regular posts
   > 
   >     <?php endif;  ?>
   >     ```
   > 

Viewing 1 replies (of 1 total)

The topic ‘problem with post_type on custom post type in Loop’ is closed to new 
replies.

## Tags

 * [post_types](https://wordpress.org/support/topic-tag/post_types/)

 * 1 reply
 * 1 participant
 * Last reply from: [niceandripe](https://wordpress.org/support/users/niceandripe/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/problem-with-post_type-on-custom-post-type-in-loop/#post-1581997)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
