You simply don’t need to specify a post_type
when calling get_post()
. The ID
for any sort of post is unique among the whole DB-posts table. So if you’re calling a post with ID = 17
$id = 17;
$post = get_post( $id );
then you’ll simply get this single post.
Note, according the Codex, when using get_post
You must pass a variable containing an integer (e.g. $id). A literal integer (e.g. get_post(7)) will cause a fatal error (Only variables can be passed for reference or Cannot pass parameter 1 by reference).
Related Posts:
- Display all posts in a custom post type, grouped by a custom taxonomy
- How to use a custom post type as front page?
- Display several random posts, but make sure a condition is met
- WP_Query to loop a Custom Field, Custom Post Types do not show
- Posts in Multiple Columns and Rows with one single loop
- Alphabetical sorting of custom post type – one letter per page
- List all posts in Custom Post Type but group dynamically by Custom Taxonomies
- How to show posts from multiple post types in a single loop? And display them separately on the same template
- Fix custom query pagination without changing site-wide posts-per-page settings
- Randomly placed sticky custom posts complemented by blog posts
- Get_post_meta() won’t return value
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Displaying custom posts only if custom meta box’s date is not expired
- Integrating Orbit slider into wordpress through custom post type
- How to get all posts except for one post from a certain custom post type?
- Create a random unique 6 digit number as custom field for custom post type
- How to insert content from another Custom Post type into Post?
- Display different content on homepage depending on post type
- WP_Query | ‘post_type’ doesn’t work
- Filter by custom taxonomy slug on a custom post type
- Change or update WordPress loop based on dropdown selection
- Can I create a loop with multiple post types and specify different $args for each post type?
- WP_Query orderby modified to include custom meta changes
- get_attached_media() on author page not working
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- How to display all posts from standard posts to custom post types in a loop with pagination?
- Calculate all custom field values in the post loop
- I would like to have different styles for my posts based on the content of each post
- Checking if Post Title is Unique as Loop Criteria
- List custom taxonomy specific to one custom post type
- Return the latest post from a custom Taxonomy and Post Type
- What to and how to proceed with CPT to make DB small and efficient?
- Full Custom Post Type List Organised by two Taxonomies
- Shortcode not working with post counter
- Get custom post type’s fields in a while loop as variables
- pagination not working for category.php (custom post types in categories)
- Custom Post Type single.php template only shows the latest post
- Tag page only display 10 posts
- How can I group posts by months and years?
- get_post_type is always post
- Trying to Create a PHP Variable for post_type that can be referenced Site Wide
- Control content before and after custom post type loop
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Query to get child pages of current page and display it in action hook
- Custom Post Type not showing in main loop
- My custom taxonomy is only displaying 1 of 3 terms
- Get post format
- Custom Post type content within a slider
- posts within custom post type all share the same content in the front-end
- displaying content of custom post type
- Display the current post in browser as the first post in a loop (for a slideshow)
- WordPress giving a 404 page when passing a year argument different than the current year
- Add Class according to the order of appearance
- Custom Sidebar in Editor (not Widget) for Custom Post Type in Genesis
- Loop Post Types with Name and Links
- Display all images from specific CPT
- Custom loop to query posts with no featured image and/or no post editor content
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- Custom Post type showing up in loop, regular posts are not showing up
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- Drop down list with posts within the “add new” page
- How to show custom post type on homepage and in categories
- using the loop in custom meta is messing up ‘add new’ post type
- Last post in loop – custom post types
- Display category name of custom posts only once in the loop
- Get Posts List of Current Selected Custom Taxonomy in Shortcode
- Custom archive page for custom taxonomy and pagination issue
- Make bootstrap 5.0 carousel dynamic using ACF and CPT UI [closed]
- Pagination Not Working When Used With WP_Query() `offset` Property
- How to avoid duplicate posts queried from custom meta?
- Excluded Custom Taxonomy Term Posts Displaying in loop
- Some posts not displaying by taxonomy term
- Looping to organize and display custom posts by category using PHP and WordPress
- My post loop needs to have 8 different post templates
- How can I group by Taxonomy on Custom Post Type while filtering out based on custom Meta
- subtracting the current post form then whole loop, which is generating all CPT titles
- Mix Facebook and Twitter feed into custom posts
- Infinite scroll doesnt work
- How to return custom posts in loop?
- custom post type loop
- Custom taxonomy page template
- Loop with Custom Post Type and Taxonomies
- WordPress Custom Post Type and sort by Tags
- After rewriting post type’s URL, the number of queries has increased dramatically
- Multiple Queries and Loops within CPT Archive
- If i have custom post type with 5 custom fields do i have to create a new loop to reference each one?
- Sorting custom post types by taxonomy (So close)
- Pagination not working with custom loop
- Pagination not working with custom loop
- Looping taxonomy in taxonomy?
- Custom Post Type Loop breaking php
- Styling first post using Advanced Custom Fields
- Loops running into each other
- Display by tag from different post types
- Loop doesn’t work in single-product.php page but works at normal page
- How do I filter a custom post type loop by a field?
- Allowing null vairiable
- WPNavi pagination links not working on custom pages
- Where paramaters of a custom function are coming from inside the loop?
- Group search results by post type, but having a unique heading for each section?