Skip to content

Instantly share code, notes, and snippets.

@pdewouters
Created November 8, 2013 17:38
Show Gist options
  • Select an option

  • Save pdewouters/7374687 to your computer and use it in GitHub Desktop.

Select an option

Save pdewouters/7374687 to your computer and use it in GitHub Desktop.
Returns the parent and child term slugs separated by a slash `parent-slug/child-slug`
SELECT CONCAT(parents.parent_slug, '/', children.slug) AS slug
FROM
(
SELECT distinct t.term_id ,t.slug AS parent_slug
FROM wp_term_taxonomy AS tt
INNER JOIN wp_terms AS t
ON tt.parent = t.term_id
) parents
INNER JOIN
(
SELECT t.slug, tt.term_id, tt.parent
FROM wp_term_taxonomy AS tt
INNER JOIN wp_terms AS t
ON tt.term_id = t.term_id
) children
ON parents.term_id = children.parent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment