0

I did many updates to a WordPress site including a WP update to 5.0.3 for a client. After the updates, many posts were missing from the home landing page and other pages. Although the categories settings were still set as they were before the updates, when I removed/published and then replaced/published the categories the pages returned to their original places.

However, the client says that there are still many posts missing from the site. I looked into the wp_posts table and checked how many records.

SELECT count(*) FROM `wp_posts` WHERE 1

count(*)    
371

However, the WordPress dashboard only shows 47 posts in total.

Is there a reason for this? Is there a way to regain those posts by fixing anything that may be wrong in the database? What other options do I have for restoring those posts?

  • What are these posts? Your SQL query doesn’t have any where, so it will show all posts. And that means that it will include attachments, menu entries, trashed posts, and so on... – Krzysiek Dróżdż Feb 20 at 21:07
  • Do you know where I can properly search for all posts (not pages or categories) in the database? Or else if there are posts missing from the dashboard, do you know of a way to try and recover them? – jonnyjandles Feb 20 at 21:19
1

Your SQL query is correct, but... There is no proper WHERE part in it:

SELECT count(*) FROM `wp_posts` WHERE 1

So it will count all rows in that table. And that table contains posts, but also much more...

First of all, this table contains column post_status. Some posts may be trashed, for example and you will still count them.

But there is even bigger problem with this count. You ignore the type of posts (column post_type). And WordPress stores many objects as "posts". For example all attachments from Media Library are stored in wp_posts table. Items of menus are also posts. And posts have revisions - they also are stored as posts.

So to check what posts are there in DB, you'll have to use query like:

SELECT * FROM wp_posts

and check all of them one by one. This will show you all posts in this table and you'll be able to check what posts are missing.

And if some posts are not in that table any more, then it will be impossible to restore them (unless you have any backups).

  • I did a query: select count(*), post_type from wp_posts group by post_type and found only 49 posts with post_type = "post". So, it looks like the dashboard is closer to the actual total of posts since it shows 47. – jonnyjandles Feb 20 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.