In WordPress How to Easily Test If a Entry is Custom Post Type!

WordPress custom post typeWordPress can hold and display many different types of content. In WordPress 3.0, we’ll have the capability to easily create and manage content via custom post types and use them in different ways. A custom post type is nothing more than a regular post with a different post_type value in the database.

If you want to be able to easily test if an entry is a specific post type? Here is a sweet little function to do so. It can be done via your theme’s functions.php file, simply paste the code:

function wpr_is_post_type($type){
    global $wp_query;
    if($type == get_post_type($wp_query->post->ID)) return true;
    return false;
}

Once done you can use the function in your themes:

if (wpr_is_post_type($type){
    ...
}

Thanks to John for submitting this cool function!