I’ve got a wordpress/mysql set up using the ‘custom post type’ which currently holds about 40,000 rows of data in the wp_posts table of the database. I’m trying to work on an SQL query that will remove all the rows of a certain custom post type in one go but it keeps telling me I’ve got a syntax error. The code I’m using is below, apologies if it’s simple but SQL is alien to me and I’m struggling to find anything in the forums.
DELETE FROM `wp_posts`
WHERE `post_type` = 'prefix-numberplates'
LIMIT 0 , 3000
There are ` around wp_posts & post_type but it won’t let me style them on here.
Any help is greatly appreciated.
This will delete from both posts and postmeta table. It left no junk in db.
Solved –
worked – took the bottom section out & it was fine.
The following removes from the posts, postmeta and term_relationships table:
Just change ‘post_type_name’ to the cpt you wish to remove.
Also change table name prefixes where appropriate.
This way makes sure you get the right table – $wpdb knows best 🙂
Try using the $wpdb class.