You can not get post ID in init
hook. The first safe hook to get post id is template_redirect
.
See this answer for more details:
Related Posts:
- How to Display Post View Count
- Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
- Exclude category from
- Change all author links in Blog roll
- The_excerpt() doesn’t parse – how to change that?
- How to only publish posts with image in it
- Add custom text automatically on each post
- Optimize CPT-function with a loop
- Show post excerpt
- Show author bio box
- Getting rid of the blog page entirely
- What function does the loop of displaying posts?
- How to change the case of all post titles to “Title Case”
- How set featured posts using checkbox in post edit screen?
- WP_Query: Why is sticky post not first item in loop?
- Display all posts from specific categories on a page
- Skip post in loop and mixin later
- How do I reorder (pop and push) items from WP_Query?
- How to exclude latest x posts from a paginated query?
- Reverse chronology of post listing
- how to display full post with pagination on home page
- Code to auto expire posts after 30 days
- Keep a fluid max number of posts on site
- This AJAX Code Doesn’t Work – Looking for elegant solution
- Custom colors for post rows based on post meta value
- How to use alternate post layout at key points in post loop?
- Showing random content / pictures from earlier posts in a sticky post?
- Custom wp_trim_words() function not trimming right
- Delete Post From Front-End and attachment permanently
- Limit function to specific post category
- Function to show random posts from a category
- Double count view in archive.php
- Group posts by year in loop
- Checking is user author of number of posts?
- Different style for most recent article
- Differentiate between posts and pages in search results
- Loop through all product posts?
- Uppercase first sentence in every post
- get_next_post() and get_previous_post() return wrong posts
- Inserting custom data to the_post() during loop
- Display post category in foreach loop with category link
- Displaying Latest Posts on a Page
- Display all posts that were published before full post on single.php
- Two loops, one AJAX loop, exclude posts in first loop from second loop, loops are in different files
- Force the “Choose from the most used tags” meta box section to always be expanded
- Get Image tag from content of post
- List authors with the last post title and order by last post date
- “Right Way” to make custom Loop respect reading settings inside admin panel?
- Only display sticky post or latest post in custom loop
- Order posts alphabetically: how to set order=asc in mysql query?
- How to order posts in an arbitrary order?
- How to make a sum of all posts displayed in a loop
- why does wordpress ignore the post args?
- First x post with another template then the others
- Loop doesn’t show title of second post and posts thereafter
- Grid post page on WordPress with Bootstrap, the_excerpt(); Problem
- Loop parent terms {display posts} AND loop child terms {display posts}
- How to add a class to each individual post?
- add bootstrap post slider with tabs
- How to add add more properties to WP_Post object in search results loop
- Adding a user’s ID behind the tag ref link address
- Add Blog to WP homepage Manually
- How to show all posts by author on buddypress profile with navigation
- ACF to select posts not displaying on blog page
- How to add automatically bootstrap 4 order-lg-1 and order-lg-2 classes for columns in foreach loop based on the count?
- Defined function isn’t showed on page
- WordPress 302 Redirect to Random Product/Post/Page
- Get post format
- Add code to a specific post’s content
- separate the post of a category by subcategory
- WordPress loop not working on static front page
- Display specific posts on home page
- The loop starting at a certain ID
- Limiting the amount of posts retrieved by the loop
- Making a wordpress page print friendly
- Error while excluding a post from another loop (using its ID)
- I need to create “View Profile” and “Edit Profile” links by incorporating the Post Title/ID, but can’t seem to manage it
- How to put the author of the post in the comments?
- WordPress Sticky Post Count “Fix” Breaking Pagecount by 72 pages!
- Function is printing twice – any suggestions?
- Diffrent layout for posts [duplicate]
- show loop id post , only first id can read
- Save All Post Permalink From A Specific Category into a .txt file
- How to Display Most View Post in the template file?
- How do I apply a wordpress function to something with no ID inside an archive page?
- Display author bio box
- Use special template for the first post in the loop
- WordPress infinite post cycle problem
- How to get all posts in gallery post format template
- List of authors posts minus very latest
- show latest authors blog post
- Post gallery as carousel
- Call image from post on index page?
- Showing content from WordPress ruins page CSS using WP_Query, without, content does not show
- Add something after all sticky posts in The Loop
- How do I get thumbnails?
- Is there a way to separate wordpress titles from their posts?
- Redirecting posts in WordPress to a specific page
- Notify Author of the post if admin deletes his post and perform some function
- When and how will php code in a user made WordPress page be executed?