Cleaning wordpress database from spam content


for my wordpress site i am cleaning my database from spam, which were somehow inserted there, but my site is working regardless. i opened phpmyadmin, and saw sam in wp_posts… so in phpmyadmin i open the table, go to the tab that says browse, go over the posts one by one, find spam posts and just hit delete and those posts are physically removed right?

but what about the table called wp_postmeta? dont all the possts in wp_posts have a corresponding entry in wp_postmeta? if so , if i delete spam posts from posts table will it be a problem or it is ok?

even if it is ok, the meta for the spam post will still remain in postmeta table if i delete just the post from wp_post. so is there a better way to clean faster and both? i didnt touch anything yet. i want to know first


Why are you going to the database directly? You can log into the site and delete those posts


Because they are not visible from control panel. the hackers did it in such a way that i can not see them from control panel


Spam are not hackers first of all. And if they are in the database, you control them from the admin section. If they are posts, then they are in pending approval status.


nothing was ever visible in admin control panel such as pending etc… the “hackers or bots made by hackers or bad people” made those posts in such a way that i never saw them in any form, from control panel. but when i go into the database, there are tons and tons of them, with links, junk content, etc…



i saw your link
but i then chekced the post type of spam posts
and they are also published, at least what i saw
but i do not see them on my contro panel
one thing i noticed, it says for post type mc_events… what is it? something from the event calendar i had may be? i checked event calendar tables and saw no spam there
and also how can i relate a post in post table to its meta in meta table? or it is ok to just delete the post and do nothing on meta table?


I don’t remember the relation honestly. Look for a foreign key that matches to the other table.


How do i know which is foreign key ? How to look for it ?

And what if i just delete post but not meta. Will it cause error ? Of course i can backup and try and see but database is so large that restoring takes forever…


A backup shouldn’t take that long.

But they tend to use primary keys as the foreign key, not always, but usually.

If it is properly done, which doesn’t mean anything in the wordpress world, it wont let you delete OR it will also delete dependency records in other tables when you do it.