deleting obsolete post types
-
I have a number of rows in the database in table wp_posts whose post_type is not valid. In general, they were created by plugins that did not clean up after themselves when they were deleted. I would like to clean up these useless rows and any related data. The plugins that created the post types are long since gone, so I cannot consult them for any advice.
I am comfortable with doing deleting rows using phpmyadmin, but am also aware of the function wp_delete_posts(). In this context I have a few questions:
1) For a given post type, is there a row in some table that defines it, or is a post type simply a value in the post_types column of the wp_posts table? In other words, if I delete all the rows of wp_posts where post_type = ‘something’, will that effectively remove the post type from the database?
2) I am aware that some rows in wp_postmeta might be related to the rows in wp_posts and I will want to delete them, too. But, is there a programatic way of identifying relations that might exist in other tables? Or do I just need to base my judgement on the table names?
3) It seems that the function wp_delete_posts() would to the job for me, but I am ensure how to use it. Should I add a snippet of code, such as the following:
$allposts= get_posts( array('post_type'=>'type-to-delete','numberposts'=>-1) ); foreach ($allposts as $eachpost) { wp_delete_post( $eachpost->ID, true ); }
to the themes functions.php, and then delete it once the job is done? Or is there a better way to do this?
Many thanks for advice on achieving this goal.
- The topic ‘deleting obsolete post types’ is closed to new replies.