Clear Terms from Taxonomy for Specific Post IDs?

Trying figure out how I can use some SQL/$wpdb->query to delete all the terms from a taxonomy that are related to specific post IDs. The following works beautifully to delete all the terms from a specific taxonomy, but I need to modify it to only remove ones associated with specific post IDs as mentioned.

// Clear Terms from Taxonomy 'post_tag'
DELETE t, tr, tt
FROM wp_terms t  
INNER JOIN wp_term_taxonomy tt ON t.term_id = tt.term_id
INNER JOIN wp_term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
WHERE tt.taxonomy = 'post_tag'

I’m also using the following to delete posts (works great):

$wpdb->query( "DELETE FROM $wpdb->posts WHERE ID IN (".implode( ", ", $postIds ).")" );

I’ve tried to do the following but it doesn’t clear the associated terms they just remain as orphaned in the DB, it just clears the relationship.

// Delete Post Terms
$wpdb->query( "DELETE FROM wp_term_relationships WHERE object_id IN (".implode( ", ", $postIds ).")" );

I’m a novice when it comes to SQL, any help is appreciated, thanks in advance!

Go to Source
Author: contempoinc

How to hide terms in edit.php

I would like to know the hook to overwrite the display of terms list for taxonomy in post edition page.
My goal is to hide some terms for a specific taxonomy that I cannot remove (generated by theme each time I try to remove it ) in wp-admin/edit.php?post_type=foo.
I´m looking for this hook without success.

Go to Source
Author: J.BizMai

Add 3rd level to Categories lists

I have a 2 level list of categories displaying checkboxes for a filter.

$terms = get_categories( array(
  'orderby' => 'meta_value',
  'meta_key' => 'orden', 
 'parent'  => 0,
    'hide_empty' => 0,  
    'exclude' => 1,  
     ) );
echo '<ul>';
        foreach ($terms as $term) {
        $categories = get_categories('child_of='.intval($term->term_id));
        echo '<li class="desplegable"><label class="desp" for="termino_' . $term->slug . '">' . $term->name . '</label>';
            echo '<ul class="cat-submenu">';
        foreach ($categories as $category) {
        if ($category->parent==$term->term_id):
        echo '<li class="submenu-item"><input type="checkbox" id="termino_' . $category->slug . '" name="termino_' . $category->slug . '" /><label for="termino_' . $category->slug . '">' .$category->cat_name. '</label></li>';
    echo '</ul>';
    echo '</li>';
echo '</ul>';

Now I need to include a 3rd level but with no result. Any tips?
Thank you in advance

Go to Source
Author: Juárez