You can use:
echo 'movie' === get_post_type( 123 ) ? 'Yes' : 'No';
But if you need to check it many times in your theme, you might consider defining your own helper function:
if( ! function_exists( 'is_movie' ) )
{
function is_movie( $mixed = null )
{
return 'movie' === get_post_type( $mixed );
}
}
It might return true when $mixed
is empty, \WP_Post
object or a post ID.
So if you want to know if there exists a movie with ID 123
:
echo is_movie( 123 ) ? 'Yes' : 'No';
or just is_move()
within the loop, to check the current post ID.
If you only need to check if the ID 123
exists, then just use get_post()
.
For example:
echo is_null( get_post( 123 ) ) ? 'No' : 'Yes';