I want to delete all post related on taxonomy.
for e.g whenever i delete a taxonomy from back-end all posts of that taxonomy should be deleted.
i tried below code with hook name is delete_term_taxonomy
<?php
add_action('delete_term_taxonomy','wp_custom_delete_taxonomy');
function wp_custom_delete_taxonomy($tt_id) {
global $wpdb; // add action here
$get_term_id = $wpdb->get_results("SELECT meta_value, user_id
FROM `wp_usermeta`
WHERE `meta_key`='term_id'
AND `meta_value` =".$tt_id."");
$post_metattid = $get_term_id[0]->meta_value;
$user_id = $get_term_id[0]->user_id;
$get_post_id = get_user_meta($user_id,'post_id',true);
$delete_all_model = $wpdb->query("DELETE p,pm,tr,d,e
FROM wp_posts as p
LEFT JOIN wp_postmeta as pm ON p.id=pm.post_id
LEFT JOIN wp_term_relationships as tr ON tr.object_id=pm.post_id
LEFT JOIN wp_term_taxonomy d ON d.term_taxonomy_id = tr.term_taxonomy_id
LEFT JOIN wp_terms e ON e.term_id = d.term_id
WHERE tr.term_taxonomy_id=".$tt_id."");
}
?>
it's not remove posts of taxonomy, anyone have idea regarding this.