wordpress tutorial, how to check custom post type in wordpress. Many we want to execute some code on custom post type or want to execute code on post. Many we want to execute some code on custom post type or some times we want to execute code on normal pages or post.
how to check custom post type in wordpress
So here is solution. You just need to just add following code into your functions.php file which you can find in your wordpress theme folder.
function check_custom_post_type() { global $wp_query; $post_types = get_post_types(array('public' => true,'_builtin' => false),'names','and'); foreach ($post_types as $post_type ) { if (get_post_type($post_type->ID) == get_post_type($wp_query->post->ID)) { return true; } else { return false; } } }
After this you can use following function in any wordpress file. For example you can use this method in single.php file.
if (check_custom_post_type()) { //Current post is a custom post type }