How to manage WordPress tags – database tweaks

WordPress database tweaks series is focused on interacting with WordPress from backend, working on a pure data straight in the database :)

In this tutorial we are going to show you how to manage WordPress tags. We have prepared useful database statements considering this topic:

-        Listing unused tags

-        Deleting unused tags

-        Changing tags name to lower/upper cases


Listing unused tags


If you let users write posts and tag them you often end up with a lot of unused tags which can be easily listed.

   SELECT name, slug
   FROM wp_terms
   WHERE term_id
   IN (
      SELECT term_id
      FROM wp_term_taxonomy
      WHERE taxonomy='post_tag'
      AND count='0'
   );


Deleting unused tags


It’s a good practice to delete unused tags to keep order on your blog . Just run this simple statement.

   DELETE FROM wp_terms
   WHERE term_id
   IN (
      SELECT term_id
      FROM wp_term_taxonomy
      WHERE taxonomy='post_tag'
      AND count='0'
   );


Changing tags name to lower/upper cases


Sometimes users can make a lot of mess when you let them publish content on your blog. Lower case tags look better, don’t they? :) If you want to change names to upper cases then you need to replace LOWER(name) to UPPER(name) in the following statement.

   UPDATE wp_terms SET name=LOWER(name)
   WHERE term_id
   IN (
      SELECT term_id
      FROM wp_term_taxonomy
      WHERE taxonomy='post_tag'
   );

One Response to "How to manage WordPress tags – database tweaks"

  1. snolan says:

    This is a gr8 little snippet for tidying up tags, thx…

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>