The 404.php
template file is used for 404
errors: i.e. no posts found.
Since there are no posts, there is no $post
object. With no $post
object, functions such as the_ID()
are not available, and will return the error you’re observing.
The fix: replace all instances of $post
-derived data with static data. e.g. replace this:
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
…with this:
<div id="post-0" <?php post_class(); ?>>
Related Posts:
- Getting a 404 error when clicking edit page
- Featured Images most often doesnt appear
- How to add category to: ‘wp-admin/post-new.php’?
- Connection lost. Saving has been disabled… (Updating Posts/Pages)
- How can I retrieve multiple get_post_meta values efficiently?
- Code to make a post sticky
- Export WordPress Posts and Meta Information in CSV format
- Delete duplicated wp_postmeta record
- Will a large postmeta table slow a site down?
- Change slug with custom field
- Better post meta efficiency?
- Setting post meta data to random value during post status transition / on publish
- 404 error after publishing a post
- Human Time Diff, change mins to minutes
- Change post format using custom field
- Exporting Data from WordPress into a flat table
- Adding Multiple Values to a Post Meta Key
- Sql syntax error
- Debugging WP routing
- Using radio button meta data from a custom meta box
- What Is meta_id In wp_postmeta?
- Add custom field automatically (add_post_meta) with value based on number of words of article
- How to generate numbers indistinguishable for the IDs of the posts
- Save re-arranged draggable post items to wordpress database
- White Blank Page when Updating and Publishing Page/Post
- Change post_date to post_modified date on post template?
- 404 on paginated blog pages
- Classic editor throws 403 error based on post content
- Custom Posts Query and meta_query Sort Order
- Encountering “Wrong nonce. Action prohibitied.” when trying to alter User Role and unable to Post via WP Admin
- why are images not full size?
- Getting value from get_post_custom
- Calling Different Custom Post Timestamps in a table
- custom post template file not shown, instead all the time 404.php
- One post on my website is going to a 404 page
- Saving custom fields to a custom taxonomy
- How to automate featured posts number? [duplicate]
- Problems with Page Not Found
- Customize rel=canonical tag for single blog post
- Change all author links in Blog roll
- How to I retrieve the ID from the Posts page?
- How to save meta checkbox WordPress
- Is there any way to tell when wp_postmeta has been updated?
- Change post author without using wp_update_post()
- if in category but only with post meta
- wp_query with ajax
- Update post meta within save_post action
- Display post number by category
- Updating post meta for checkbox
- Saving Post Data in Another Database
- Posts and Pages: 404 Page not found
- Custom permalink for each post
- How can I tell if a post has been published at least once?
- Automatic blog page with custom design [closed]
- Show number of posts by logged in user
- How does WP decide how to display a page
- When sending a newsletter -not with wordpress- the server has 100% cpu [closed]
- Retrieve data from post meta meta_key having ‘_product_fq_image’ while having author_id and post type is PRODUCT
- Insert data from custom created PHP page into wp_postmeta table
- Adding a meta box to determine the sidebar [closed]
- saving/reading custom field value does not work – no value gets POSTed
- Get post category as a separate string and url
- My post does not show up
- Prevent 404 of Author pages without posts
- Post meta not working
- Select another post in a post meta like a parent page is selected while editing a page
- My posts are getting to Auto draft when I try to Publish
- Private post caught in endless redirect loop
- What is proper filter or hook action to add data to the $post object?
- Blogposting Schema & Structured Data without plugin
- Display Updated Date Instead of Published Date
- Many buttons not functioning in WordPress dashboard (as admin)
- How do you update post date (year only) in a separate custom field?
- Add postmeta to all blog posts
- Bulk Post update_post_meta
- Re-order Category Meta-data
- How to hide meta from search result only on pages?
- including 404 page in post page
- Grab meta data before post is saved
- How to fetch posts that are stored in the different table than the default table (wp_posts)?
- alt of attached image in post / pages
- Get the correct meta_value with get_post_meta
- Filter question list on substring of metavalue
- Show posts between two Custom Fields date
- Add custom class to existing menu items from custom meta
- Authentication over CURL
- Get post title by Alphabet
- Show related (archive) month and year to post
- Getting 404 when using rewrite rule for posts
- Password-protected Posts lead to 404 Error
- How enter custom post meta or custom field on box post list archive page?
- WP_query sort by custom meta_key “price”
- If meta_key exists then don’t select this post?
- Cannot Create a new Post [closed]
- What effect can a large wp_post table have on overall site performance?
- Site ‘Categories’: save an admin global setting with post metadata [closed]
- Admin notice on wp_insert_post
- How to make internal links creating plugin to respect ACF?
- Post pages are redirecting to the 404 page in wordpress
- Posts Page in WordPress loading bare HTML of my homepage