Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#14304 closed defect (bug) (invalid)

problem with post_type on custom post type in Loop

Reported by: niceandripe's profile niceandripe Owned by: frankperez87's profile frankperez87
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

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

Change History (4)

#1 @frankperez87
13 years ago

  • Owner set to frankperez87
  • Status changed from new to accepted

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;  ?>

#2 @niceandripe
13 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

yes thankyou.

#3 @duck_
13 years ago

  • Keywords custom post types removed
  • Milestone Awaiting Review deleted
  • Resolution fixed deleted
  • Status changed from closed to reopened

#4 @duck_
13 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.