[wp-trac] [WordPress Trac] #12588: Add function to check if current page is a custom post type

WordPress Trac wp-trac at lists.automattic.com
Sat May 8 17:04:58 UTC 2010


#12588: Add function to check if current page is a custom post type
----------------------------+-----------------------------------------------
 Reporter:  sirzooro        |        Owner:  nacin   
     Type:  defect (bug)    |       Status:  reopened
 Priority:  normal          |    Milestone:  3.0     
Component:  Administration  |      Version:  3.0     
 Severity:  normal          |   Resolution:          
 Keywords:  has-patch       |  
----------------------------+-----------------------------------------------

Comment(by sirzooro):

 Replying to [comment:16 scribu]:
 > Replying to [comment:14 sirzooro]:
 > > BTW, please make sure `is_post_of_type()` will return `false` when
 called from non-post pages (e.g. home page, category or date archive). I
 am going to test this within few next days and will let you know if there
 are any issues.
 >
 > Why?

 I would like to use following code in plugin:
 {{{
 if ( is_post_of_type( 'mytype' ) {
   do_something_special();
 }
 }}}
 I think other people would like to do the same.

 > > One more thing: previous function version allowed to skip $types
 param, and uses all post types (returned by get_post_types()) as default.
 Please change is_post_of_type() to follow this.
 >
 > I disagree. It's meant to check agains specific post types; that's why
 it's called is_post_of_type() you know...

 I need this to do some things for all post types, e.g. print meta headers
 in <head>, which are stored as post meta data. The easiest way would be to
 just check if `is_post_of_type()` will return `true`. But this is not a
 problem - I can use `is_post_of_type( get_post_types() )` instead.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12588#comment:17>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list