Issue with tax_query
-
Trying to delete all posts of a certain type (in this case ‘chart’) in a certain custom taxonomy (in this case ‘site’) that belong to a term when that term is deleted. Here’s what I have at the moment:
add_action( 'delete_term', 'remove_site', 10, 3 ); function remove_site( $term_id, $tt_id, $taxonomy ){ if ($taxonomy != 'sites') return false; $args = array( 'numberposts' => -1, 'post_type' => 'chart', 'tax_query' => array( array( 'taxonomy' => 'sites', 'field' => 'id', 'terms' => $term_id, ), ), ); $posts = get_posts( $args ); foreach ($posts as $post) { wp_delete_post( $post->ID, true ); } }
However, this does nothing. If I remove the tax_query (or make it a single level array), all posts of type ‘chart’ are deleted, so it must be something to do with the tax_query but I’m using the exact same query successfully elsewhere within a get_posts… I am, in fact using the exact same $args array elsewhere successfully, so I’m stumped.
I’ve checked that term_id is set properly, and it is (returning an integer) and $taxonomy is indeed ‘sites’.
- The topic ‘Issue with tax_query’ is closed to new replies.