SQL to update custom post taxonomies

You will need to join four tables to get categories of custom post type “review”

  1. wp_term_relationships
  2. wp_posts
  3. wp_term_taxonomy
  4. wp_terms

by using following query you can get list of categories applied to your custom post type:

SELECT *
FROM wp_term_relationships AS tr
LEFT JOIN wp_posts AS p ON tr.object_id = p.ID
LEFT JOIN wp_term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
LEFT JOIN wp_terms AS t ON t.term_id = tt.term_id
WHERE p.post_type="review" AND tt.taxonomy = 'category';

and then update the type of these categories to your new custom category (i.e. “review-category”)

UPDATE wp_term_taxonomy SET taxonomy = 'review-category' WHERE term_taxonomy_id IN (1, 71, 72);

change where clause according to your category ids.

For more information visit following WordPress documentation links:
Database_Description
WordPress_Taxonomy

Leave a Comment