Title: SQL code to bulk remove tag references
Last modified: August 19, 2016

---

# SQL code to bulk remove tag references

 *  [christopherross](https://wordpress.org/support/users/christopherross/)
 * (@christopherross)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/sql-code-to-bulk-remove-tag-references/)
 * I’ve got a WordPress website that I’ve been running an auto tagger on for a while
   now, which has cause the database to grow to simply be too large and I need a
   little help cleaning it out.
 * What I’d like to do is first, reset the _term_taxonomy table to count most tags
   as having 0 counts.
 * UPDATE wp_term_taxonomy SET count = 0 WHERE count < 20;
 * Next (and here’s where I’m hoping there’s a better suggestion … I need to purge
   all contents of both the wp_term_relationships and wp_term_relationships table
   where the wp_term_taxonomy count value is 0.
 * I know I can do this by looping but this’ll cause serious server load issues,
   so is there a quick piece of SQL that anybody can recommend?
 * [**moderated–bump removed.** Please refrain from bumping as per [Forum Rules](http://wordpress.org/support/topic/68664?replies=6)]

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Nagmay](https://wordpress.org/support/users/gabrielmcgovern/)
 * (@gabrielmcgovern)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/sql-code-to-bulk-remove-tag-references/#post-1213728)
 * I had the same problem and ended up with almost 40,000 tags. Here’s what I did:
 * 1) Open wp_admin/template.php
 * 2) Find line 721:
 * > $args = array(‘offset’ => $start, ‘number’ => $pagesize, ‘hide_empty’ => 0);
 * 3) Temporarily change to:
 * > $args = array(‘offset’ => $start, ‘number’ => $pagesize, ‘hide_empty’ => 0,‘
   > hide_empty’ => 0);
 * This causes your post tag list (in the admin area) to display by ‘post count’
   rather then ‘tag name’.
 * You can then click ‘screen options’ to display 999 and begin to safely delete
   the low count tags.
 *  [shoffy](https://wordpress.org/support/users/shoffy/)
 * (@shoffy)
 * [15 years, 12 months ago](https://wordpress.org/support/topic/sql-code-to-bulk-remove-tag-references/#post-1213748)
 * Hey Gabriel, thanks for the help, but I think your path should be:
    wp_admin/
   includes/template.php
 * Not saying you’re wrong, just saying that’s where I found mine. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘SQL code to bulk remove tag references’ is closed to new replies.

## Tags

 * [sql](https://wordpress.org/support/topic-tag/sql/)
 * [tags](https://wordpress.org/support/topic-tag/tags/)
 * [wp_term_relationships](https://wordpress.org/support/topic-tag/wp_term_relationships/)
 * [wp_term_taxonomy](https://wordpress.org/support/topic-tag/wp_term_taxonomy/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [shoffy](https://wordpress.org/support/users/shoffy/)
 * Last activity: [15 years, 12 months ago](https://wordpress.org/support/topic/sql-code-to-bulk-remove-tag-references/#post-1213748)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
