• Is it possible to force an update to the tag count?

    I have a custom piece of code that strips common tags errors from a WP installation using the code

    $mylink = $wpdb->get_row("UPDATE wp_term_taxonomy SET count=0 WHERE term_id = ".$termid);
    $mylink = $wpdb->get_row("DELETE FROM  wp_term_relationships WHERE term_taxonomy_id = ".$termid);

    Is there a shortcut to force WordPress to update the count column in wp_term_taxonomy?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Might look at the wp_delete_object_term_relationships and wp_delete_term functions in wp-includes/taxonomy.php.

    wp_delete_object_term_relationships uses wp_update_term_count

    grx3

    (@grx3)

    Here is the code I used after I built a custom auto-tagger. I noticed that wpdb get’s iffy using about 20,000 records and had to user mysql instead. I will post the full code over on hawkenterprises.org in a few but for now here is the code.

    <?php
    define('WP_USE_THEMES', false);
    
    /** Loads the WordPress Environment and Template */
    require('./wp-blog-header.php');
    $terms = array(30,23,28,25,33,31,26,27,29,24,32);
    wp_update_term_count($terms);
    ?>

    I’m sure I don’t need to load everything since it’s just in taxonomy.php but this is less lines. The terms array is IDs of the terms you want to update. Note if ran properly this page will output nothing.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Force update to tag count?’ is closed to new replies.