An alternative to your way would be to access the $post
global:
global $post
echo $post->ID;
But
- It won’t make a noticeable difference, either way
- If you want to increase efficiency, you ought to be looking elsewhere…
EDIT, pertaining to comments:
what about
get_the_ID();
?
–> Needs to be run inside the Loop.
i have tried both options (get_the_ID and accessing $post global) both give me a wrong id.
If the latter is the case, you, or some plugin you are using, has not properly reset postdata.
You say to look elsewhere… where should I be looking?
I have no idea what it is you are writing. But if you experience resource bottlenecks or inefficiency, retrieval of the current post ID is likely not the cause.
Related Posts:
- Get page ID of page that is set as the posts page
- Are post ID’s reliable?
- Get current post id in functions.php
- get all posts ID from a category
- Get the current post ID as a variable in Javascript
- Is post ID number always incremental n+
- Are all ID’s used unique?
- $post->ID displays wrong ID
- At my posts archive page, outside the loop, get_the_id() returns the top most post’s ID
- Showing random content / pictures from earlier posts in a sticky post?
- Get the post_id of a new post
- get post id in while loops outputting page id
- How can I display a specific user’s first published post?
- Undefined variable post_id in custom quick edit coloumn
- Getting post id from wp_insert_post_data function?
- Does an article (post) id ever change?
- How to get the post’s parent ID?
- Can a page_id and a post_id be same?
- Getting current post ID in functions.php
- Buddypress activity id
- How blog page in WordPress works : blog page retrieve first post ID
- Post-ID in url differs from $post->ID
- Why is my Blog Page ID == First Post ID?
- current post with current author
- Is it possible to change post id for an already added menu item in WordPress?
- Get ALL post ID’s export list (Only id’s. Php or sql not important )
- How to get next post ID?
- Search results posts_orderby and ID
- Retrieve post ID from “querying” URL
- How to get a post’s content? [closed]
- obtain the author id given the post id
- How to get ID of the page included with get_page()?
- How to I retrieve the ID from the Posts page?
- Crazy Question – Updating Post ID
- Why I can not I use the variable outside my function?
- retrieve the oldest post id
- WP_Query custom field pass the post id
- Accessing Post ID Within Loop
- How do post IDs work in WordPress?
- Are post, page and category IDs unique to each other?
- The loop starting at a certain ID
- linking to post outside the loop
- Widget to show posts in the sidebar basing on its IDs
- Get a post’s ID
- Making posts permalinks consistent numbers
- How to get post id of last approved comment?
- How to get the post id (of the parent custom custom type) in a loop inside a widget?
- Get post slug and match with menu item slug to change css
- WordPress Post ids big increment
- Reuse old post ID for new post after deleting post
- Get post attachment with post id
- How can i take all ids from untrash_post action?
- How do I apply a wordpress function to something with no ID inside an archive page?
- Get from the dashboard the ID of the current post being edited
- Only get post_id [duplicate]
- Surrogate ID for posts, is there an alternative field in the posts table?
- Is it possible to have dynamic post id # in add_menu_page()?
- Using Post ID and Page ID in same function
- unused post IDs
- Custom post page has attributes of latest post [closed]
- Can I get custom post items in select box (dropdown)
- What is $post->ID
- View post with specific category id and name which I selected in the backend (drop-down option)
- How to get post ID after removing that post?
- Rewriting post slug before post save
- Change the default number of posts to show on mobile version
- How can I pass $post object to ‘save_post’ add_action?
- Insert posts in two tables
- custom wordpress post loop – hide iframe content
- how can I put an image in a post with original size
- Set terms in a custom post
- minimum requirement to add posts via database
- Delete and perform a fresh install of WordPress
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- Overwrite posts/pages via import
- Auto-realod with new posts // Ajax call
- How many posts does the loop return?
- Blog Post On Home Page Displaying Page Published Date Not Post Published Date
- Divs appearing everywhere in post content
- Post Title List on home page with time
- Get x recent posts by author?
- Adjust the order for returned posts
- Post in bulk based on category template
- user_has_cap filter allows “edit_others_posts” but not is not allowing updating/publishing
- Add data attribute of post_id for Internal links
- Menu Items disappearing/being empty on save or post edit
- Display/Filter post using if else statement
- Nestling Posts Under Page & Justify Text
- Strange behaviour in WordPress admin
- How do you update post date (year only) in a separate custom field?
- sometimes on saving a post as draft, it says Access Denied You don’t have permission to access “mywebsite.com/wp-admin/post.php”
- How do I change the post title’s link on the posts page?
- WordPress text field in array problem
- Get query result according to merged array
- Custom URL Structure for posts with subcategories
- Possible to display X number of authors posts from another WordPress site?
- List posts that are in the same category as the current post title
- How to get pagination working with “Pending” Posts
- Do I need to create a multisite for querying posts from multiple WordPress sites?
- WordPress Ajax load doesn’t work