Posted By

jonasethomsen on 07/11/13


Tagged

php post wordpress type conditional boolean custom


Versions (?)

Check if current post type is a custom post type – WordPress


 / Published in: PHP
 

Check if current post type is a custom post type – WordPress. Returns a true/false-statement.

Can be used outside The Loop.

  1. function is_custom_post_type() {
  2.  
  3. global $wp_query;
  4.  
  5.  
  6. $post_types = get_post_types(array('public' => true,'_builtin' => false),'names','and');
  7.  
  8. foreach ($post_types as $post_type ) {
  9. if (get_post_type($post_type->ID) == get_post_type($wp_query->post->ID)) {
  10. return true;
  11. } else {
  12. return false;
  13. }
  14. }
  15. }

Report this snippet  

You need to login to post a comment.