the_ID()
must be within The Loop.
from the_ID codex page
global $post
will merely get the last post that was set as the global post object which will depend greatly on what is done in the rest of the request. If somewhere in your header template, page template or content template you change or modify the global $post object that’s the one you will get back when you bring it into your function.
Related Posts:
- How to change default position of WP meta boxes?
- Rewriting a custom-post-type permalink with taxonomy term?
- group search results by post type?
- Hide “Add media”, HTML editor from TinyMCE
- Edit the “Post updated. View post” link
- How often do you need to register_post_type?
- Ordering Post 2 Post admin meta box by meta from CPT
- How to sort list of custom posts to get view like a tree of posts under categories and their children’s categories?
- How to append text to title of Custom Post Type post (without affecting all titles on page)?
- URL rewrite and navigation structure for wordpress custom post type
- Randomly placed sticky custom posts complemented by blog posts
- How to create a repeatable / reusable divs in the metabox?
- wp_list_pages doesn’t work in hierarchical custom post type
- Hierarchical Custom Post Types or Similar
- Mass convert MySQL data entries into custom post type?
- How do I get the child category posts from a custom post type?
- Sort admin area by custom Event Date field
- How to change the admin menu “Pages” to something else
- Function error – Use of undefined constant ‘pre_get_posts’ – assumed ‘‘pre_get_posts’’
- Exclude child pages from archive.php
- Placeholder in HTML editor text area?
- Displaying media for custom post type
- Using The REST API How To Pull All Custom Posts?
- How to save custom taxonomy from front end post submission
- Insert and then update post_type by wp_update_post
- Template for custom post with custom taxonomy
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- Visual editor issue by having multiple tiny mce editors in a CPT
- orderby rand is not working for a custom post types
- custom home page and custom index page?
- list taxonomies from a custom post type
- Change custom post type permalink to show name of post from another custom post type?
- cpt and page sharing same base permalink
- Set up post page like JAMA articles
- A custom post type in another post type
- Displaying and searching Custom Posts
- Importing Data from a Non-WordPress database, into WP
- It’s possible to hide body copy box for a custom post type?
- Categorise Custom Post Types
- Add ‘last’ class to second post in featured post loop
- in_category for custom post types
- sort post types by amount of views
- Trouble with pagination
- User-submitted reviews of different custom post types
- Listing all slugs?
- Template Hierarchy for custom post type pages
- I can no longer post or even save a draft, getting the error “A post type mismatch has been detected.”
- My custom taxonomy is only displaying 1 of 3 terms
- Custom Field not saving in WordPress
- custom post type by author – wp job manager
- How can I modify a custom post type and custom page template for a child theme if all content seams to be handled by theme’s ‘native’ plugin?
- Change Custom Post Type singular_name through function/filter
- Custom Post type showing up in loop, regular posts are not showing up
- filter the_content, custom post type, and wp_query
- Best way for a plugin to define a custom post type archive template?
- WordPress custom post type numeric pagination with ajax
- How to make an API call to a custom post type but filtering by meta value?
- Settings -> Reading -> Posts Page ->Blog — is not working in my website
- Does non-content posts have a negative impact on SEO?
- Sudden 404 pages on product category archives
- Some posts not displaying by taxonomy term
- Update post status from “publish” to “trash” prior to year 2018
- Simple way to hide\show an announcement (just a div) on homepage?
- Create Custom page with custom domain
- Archive for custom taxonomy
- How can we display full post on home page rather than excerpt
- WooCommerce change
- Custom post types & Advanced Custom Fields code is not working
- Working with Custom Post Type
- Question on templates
- What is WordPress’ custom post type ‘Logs’?
- Custom taxanomy and custom post type – pagination leads to 404
- How can I load Template file from wordpress plugin
- Getting all custom post taxonomies and exhibiting only part of them
- Author archive custom posts only?
- update a posts of other custom post type
- How to return custom posts in loop?
- Custom post type AND custom taxonomy are not connected
- How to delete comma from the end of results? [closed]
- How can i call a custom method on submission of a custom plugin post type?
- Front end page submission form does not attach custom post type
- Pagination custom post types outside loop
- How do I get a nested query to only display content that the main query outputed
- Get post id of permalink for a specific custom post type?
- Displaying custom post types with taxonomy
- Using one custom taxonomy.php for two custom taxonomies?
- If you’re calling a dynamic css inline style does that div have to be in the loop?
- If i have custom post type with 5 custom fields do i have to create a new loop to reference each one?
- Add taxonomy to custom post type archive
- posting twice from an array?
- Custom post type – permalink
- How to show animal lineage/pedigree in WordPress?
- WordPress 3.1 – Tag page not showing posts from custom post type
- How would you feed Custom Post Types to Facebook?
- Need Help With Worpdress Parent Child Attribute
- create category upon saving post and save post in that category
- Custom Plugin w/ Custom Post Types – Custom Posts Are Showing at all Privilege Levels – Is this possible to adjust?
- WordPress getting problem with pagination [duplicate]
- Attaching multiple custom taxonomies to one CPT?
- custom post types shortode stays on top of other page contents. Is there a bug?