Clear Terms from Taxonomy for Specific Post IDs?

So if you’re sure you want to delete the actual term as well as the relationship that assigns the term to the post, this will do it (tested and works for me): delete term from wpterm_taxonomy term, wpterm_relationships rel where term.term_taxonomy_id = rel.term_taxonomy_id and rel.object_id IN (1) ; And obviously replace the ‘1’ there with … Read more

Cannot delete or edit a single term in a custom taxonomy, taxonomy name is wrong?

Credit for this answer goes entirely to CodeMascot: Create and move terms for taxonomies After troubleshooting, I believe the issue is because I initially created the custom taxonomy with the name Purpose, but then changed it to purpose at another time. Calling $object->taxonomy returns Purpose on the affected term, while all the others listed in … Read more

WP_Query to output chosen term and posts with no term assigned

It’s actually pretty simple: You’ll want to use an OR relation, and use the NOT EXISTS operator for selecting posts that are not assigned to any terms in the specified taxonomy. $tax_query[] = array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘location’, ‘field’ => ‘name’, ‘terms’ => $location, ), array( ‘taxonomy’ => ‘location’, ‘operator’ => ‘NOT … Read more

Count tags for a specific category

count how many posts are tagged but only include those posts that belong to a specific category You can’t do that via get_terms(), but you can make a WP_Query query and use the $found_posts property to get the total posts. So for example, in your foreach, you can use the tag and cat parameters like … Read more