Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

PHP Notice error (when on 404 page)

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:

  1. Getting a 404 error when clicking edit page
  2. Featured Images most often doesnt appear
  3. How to check if post meta key exists or not in wordpress database
  4. How to add category to: ‘wp-admin/post-new.php’?
  5. Connection lost. Saving has been disabled… (Updating Posts/Pages)
  6. How can I retrieve multiple get_post_meta values efficiently?
  7. Code to make a post sticky
  8. How to allow hidden custom fields to be added from wp-admin/post.php?
  9. Export WordPress Posts and Meta Information in CSV format
  10. Fatal error: Call to undefined function post_exists()
  11. Delete duplicated wp_postmeta record
  12. Will a large postmeta table slow a site down?
  13. Update all posts automatically when using post_meta
  14. How to batch update post content with custom post meta value
  15. Change slug with custom field
  16. Better post meta efficiency?
  17. Setting post meta data to random value during post status transition / on publish
  18. 404 error after publishing a post
  19. Edit meta data does’t work with custom sql
  20. Some posts returning 404 instead of displaying post
  21. Custom post type single (permalink) throws a 404 error
  22. Human Time Diff, change mins to minutes
  23. Change post format using custom field
  24. Unable to modify(update) posts – Page not found
  25. Does WP get all post_meta on POST page?
  26. Sanitizing `wp_editor();` Values for Database, Edit, and Display
  27. Exporting Data from WordPress into a flat table
  28. Adding Multiple Values to a Post Meta Key
  29. Sql syntax error
  30. Debugging WP routing
  31. Using radio button meta data from a custom meta box
  32. Fatal error post.php help :(
  33. ‘Invalid post type’ error when importing from one site to another
  34. What Is meta_id In wp_postmeta?
  35. Checking if a post with certain meta value exists
  36. How to permanently delete a post meta entry?
  37. Add custom field automatically (add_post_meta) with value based on number of words of article
  38. How to generate numbers indistinguishable for the IDs of the posts
  39. Modify WP_Post before processing
  40. Save re-arranged draggable post items to wordpress database
  41. White Blank Page when Updating and Publishing Page/Post
  42. I would like to give special promotion for the first 100 posts in my blog? Can anyone tell me how to do that?
  43. Change post_date to post_modified date on post template?
  44. Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
  45. How can I sort posts by the date and a custom meta field?
  46. is there a way to show the the post title after the image?
  47. Get Meta Key Value While Saving Post
  48. 404 on paginated blog pages
  49. Classic editor throws 403 error based on post content
  50. How to display content from the main blog on another from multisite network as it would be its own
  51. Force the “Choose from the most used tags” meta box section to always be expanded
  52. Meta value does not save for scheduled posts
  53. Custom Posts Query and meta_query Sort Order
  54. Encountering “Wrong nonce. Action prohibitied.” when trying to alter User Role and unable to Post via WP Admin
  55. why are images not full size?
  56. How to compare two posts including their meta fields on a scalable base?
  57. Why does my site often display 404 on subpages?
  58. Getting value from get_post_custom
  59. Blank page when saving edits on post
  60. Calling Different Custom Post Timestamps in a table
  61. Is it possible to paste a link without tags and make it directly a link in a post?
  62. custom post template file not shown, instead all the time 404.php
  63. One post on my website is going to a 404 page
  64. Cannot retrieve a custom RSS field from posts
  65. How do I locate the exact location where this error is occurring 404 page not found
  66. 404 error on default post type and default taxonomy fronted page
  67. Saving custom fields to a custom taxonomy
  68. How to automate featured posts number? [duplicate]
  69. What do these phpMyAdmin errors mean on my WordPress databaes?
  70. Problems with Page Not Found
  71. Customize rel=canonical tag for single blog post
  72. Change all author links in Blog roll
  73. How to I retrieve the ID from the Posts page?
  74. How to save meta checkbox WordPress
  75. How to calculate the average of a post meta value(Numeric) of a specific author
  76. Is there any way to tell when wp_postmeta has been updated?
  77. getting “Object of class WP_Post could not be converted to string” – when it is a string
  78. wpColorPicker – problem with implementation to post meta
  79. Change post author without using wp_update_post()
  80. if in category but only with post meta
  81. wp_query with ajax
  82. Update post meta within save_post action
  83. Display post number by category
  84. Updating post meta for checkbox
  85. Saving Post Data in Another Database
  86. Posts and Pages: 404 Page not found
  87. Custom permalink for each post
  88. How can I tell if a post has been published at least once?
  89. Is there a way getting post fields using `transition_post_status`
  90. Automatic blog page with custom design [closed]
  91. Add multiple meta keys to a post at once
  92. Show number of posts by logged in user
  93. How does WP decide how to display a page
  94. When sending a newsletter -not with wordpress- the server has 100% cpu [closed]
  95. Retrieve data from post meta meta_key having ‘_product_fq_image’ while having author_id and post type is PRODUCT
  96. Insert data from custom created PHP page into wp_postmeta table
  97. Adding a meta box to determine the sidebar [closed]
  98. The loop starting at a certain ID
  99. saving/reading custom field value does not work – no value gets POSTed
  100. Simple Custom Metabox Not Saving
Categories posts Tags 404-error, errors, post-meta, posts
Do i need the git directory?
How to not show tags if the post doesn’t have any?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress