Empty WordPress custom post Data from MySql database table

Sometime while working on huge WordPress site, we may need to remove the old custom post data. Today we will discuss on how we can perform this action. For this we need to have phpmyadmin access,

then in SQL run the below code one by one as shown in figure above,

DELETE FROM wp_posts WHERE post_type='post_type';
DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT id FROM wp_posts);
DELETE FROM wp_term_relationships WHERE object_id NOT IN (SELECT id FROM wp_posts);

The first line deletes all posts with that post_type from wp_posts.

The second then removes any post metadata from wp_postmeta that is no longer tied to a post.

The third line removes and tags or categories from wp_term_relationships that were tied to that post type. This line should be omitted if you intend to create more posts of the given post_type in the future.

Source : Stackoverflow

One Reply to “Empty WordPress custom post Data from MySql database table”

  1. Tara, I really enjoyed this post. I love the idea of breaking a little self-imposed rule once in a while to see that the sky doesn’t come crashing down. Everybody needs a &#-a20;mental8he2lth” day off once in a while. When we give in to ourselves once in a while we become softer around the edges making it easier synchronicity to occur in our lives. Thank you for this wonderfully affirming post.[]

Leave a Reply

Your email address will not be published. Required fields are marked *