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';
Related Posts:
- Is it possible to request several post types from a feed?
- What is the meaning of the various post messages?
- wp_list_filter() and supports
- What does get_current_screen() do?
- Post types – Normal Post – Image
- WordPress register_post_type Invalid post type
- How to edit default post settings
- Conditional based on post meta
- Querying for multiple post types in SQL
- Displaying only the current category in template page
- How to get all CPT names into WP_Query ‘post_type’ parameter?
- Show post type taxonomy
- wp_dropdown_pages() returns empty string for post type anything other then page
- Target Post Type from array Query
- Use register_post_type() to modify an existing post type
- How do i know the current post type when on post.php in admin?
- Are captions stored anywhere?
- Overwrite rewrite-slug of built in post-type ‘post’
- How do I implement custom fields without using any plugins?
- Get All IDs Of A Post Type Using WP_Query
- List All Post Types in Admin view using /wp-admin/edit.php?post_type=
- Better to use a post type archive, page template, or shortcode for generating a highly configurable CPT archive?
- Dynamically Set WordPress Post Title To The Category Name
- Registered Post Type Isn’t Showing in Admin Menu
- pop-up lighbox with AJAX
- Custom Post Type causes Page Not Found
- How do I make search results include ONLY pages, no posts?
- wp_query for displaying attachments with a tag
- How can I pick a single post from the latest 3?
- save_post not working with attachments
- Multiple post type queries (with specific arguments for each)
- Undefined property: WP_Post_Type::$ID
- Understand post type
- Should I be using custom post types for this or terms and taxonomies?
- get_post_type() in in_array doesn’t work for some reason
- WP_Query | ‘post_type’ doesn’t work
- How to restrict wordpress search to pages and disable products listing search?
- View the number of entries recorded per day
- I don’t arrive to do order_by title when i have a conditionnal year in a request
- Does only custom post type have post type archive pages?
- Search query -> Show all pages except certain template
- wp_customize – detect post type to show/hide customizer options
- child of post type (custom)
- Query reset problem or flawed code to enable custom post type query
- Limit amount of posts made within a custom taxonomy
- How to retrieve more posts from a custom post type that are in the same category as the current post
- force permalink slug for page vs post_type slug parent
- Filter post_type thumbnail in Search result
- How to build a simple nav system of custom post type categories and its posts?
- Define add_editor_style to specific post types?
- get_the_post_thumbnail_url(‘full’) returns empty from custom post type
- How to get Post Type from the functions.php file
- single-{post_type}.php not working
- how to get random post id by using post type
- Adding in support thumbnail removes editor
- Can I change my post type to anything and my site still work?
- get_post_types – exclude multiple post types by name
- Remove taxonomies using register_post_type_args
- post_type internal ID?
- How do you determine if a result in a search query is a post or a page?
- Setup database structure with books, authors, languages etc. for publishing house [closed]
- How to check if it’s edit.php & post_type is set?
- Dynamic pages for linked categories and content
- get_post_types not working properly in admin
- Post types translation
- Replace Post-Title with variable
- Custom wp_query differs on index page and category page
- Post Type => Any conundrum
- Pros and Cons of Post Types vs. Multiple Blogs
- Why would post_type be ignored in this query?
- Filter Media by attached page or blog post in Library
- Unique IDs for Post Types and Taxonomies
- Only show meta on one post type on search results page
- How to get all post status
- Get all post types that supports tags
- Quick Draft widget (dashboard.php) using custom post_type
- Shortcode is not showing content when placed in editor (post_type = page)
- Distinguish between page and post in function
- Filter by Post Type
- How to create custom post type selection to nav menu
- How can I get the Post ID and Post Type within a Must Use Plugin?
- How to mix 2 kinds of post types
- Change Custom Post Type to Post + Category
- Shortcode in excerpt
- post_type not working when tag__in is present?
- Custom post type post_type_link gives “page not found” on any other custom post type
- How to set a default CPT template and create post attribute´s display rules?
- custom post permalink
- How to set “manage categories” capabilities on a post type taxonomy but not on the general categories?
- Get_posts not returning any posts when used with switch_to_blog
- Pulling in Related Posts based on Post Type array
- Disable default posts (Posts,Pages,Comments and Media) in wp-admin
- Custom Filter using meta_value in wordpress admin list not working
- Problem with permalink structure for WordPress custom post_type archive template
- Why does ‘exclude_from_search’ exclude a custom post type from WP_Query?
- Taxonomy Category category.php not working
- add post type pram to wp shortcode
- How do i retrive a post from a custom post type
- Quering array of post types & pagination. Articles are repeating sometimes on different pages
- custom taxonomy not return in the code