SQL Statement – Mass Delete Custom Post Types

Trust you have backed up your wordpress database. In any case, as the article suggests, worth trying with a select statement first to see which posts are returned:

SELECT DISTINCT ID, post_title, post_type, post_status, d.taxonomy, e.name
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON ( a.ID = b.object_id )
LEFT JOIN wp_postmeta c ON ( a.ID = c.post_id )
LEFT JOIN wp_term_taxonomy d ON ( d.term_taxonomy_id = b.term_taxonomy_id )
LEFT JOIN wp_terms e ON ( e.term_id = d.term_id )
WHERE d.taxonomy = 'estate_agents' AND a.post_type="os_estate" AND e.term_id = 9098

Then, if you’re happy:

DELETE a,b,c
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON ( a.ID = b.object_id )
LEFT JOIN wp_postmeta c ON ( a.ID = c.post_id )
LEFT JOIN wp_term_taxonomy d ON ( d.term_taxonomy_id = b.term_taxonomy_id )
LEFT JOIN wp_terms e ON ( e.term_id = d.term_id )
WHERE d.taxonomy = 'estate_agents' AND a.post_type="os_estate" AND e.term_id = 9098

Specifying DELETE a,b,c means that only rows in the wp_posts, wp_term_relationships and wp_postmeta tables will be deleted; rows in wp_term_taxonomy (d) and wp_terms (e) will not.