Skip to content

Delete Content By Term ID

Matthew Petrovic edited this page Mar 12, 2015 · 1 revision

Given a term id, will delete all nodes which have that id. Can handle 750 nodes easily.

	$tids = func_get_args();
	
	$q = db_select('field_data_og_vocabulary', 'ov')
	->fields('ov', array('entity_type', 'entity_id'))
	->condition('og_vocabulary_target_id', $tids)
	->execute();
	  
	$ids = array();
	foreach ($q as $r) {
		$ids[$r->entity_type][] = $r->entity_id;
	}
	
	foreach ($ids as $type => $k) {
		drush_print('Deleting nodes of type '.$type);
		entity_delete_multiple($type, $k);
	}
Clone this wiki locally