WordPress Tip: Get Rid of Trashed Posts

A client emailed me today and asked me why their blog post was still showing up when they had deleted them. I went into their WordPress dashboard and couldn’t find the post but there it was on the website loud and clear. Upon further investigation I realized that the post was deleted – or rather trashed.

When you move an item to your trash in WordPress, it doesn’t get deleted until after 30 days and the entry is still in the database. Good to know. So… you can 1. delete it permanently, thus ensuring it is in fact deleted and any queries you make that would otherwise match that entry wouldn’t find it or 2. you can check your original query and ensure you’re only catching published items. I chose the latter as forcing my clients to delete their posts permanently is a hard restriction that I don’t want to set. What if they changed their minds and want to restore their trashed post later?

Anyway, it was a simple fix and something to keep in mind for future development. So for those who are having this issue and finding that there are posts that they just can’t find, I suggest look in the trash! And add this to your query:

AND wp_posts.post_status = ‘publish’

Done and done.