Skip to content

Instantly share code, notes, and snippets.

@seanbehan
Created September 13, 2018 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanbehan/994cd96a2a3febc94cb5d50f5364de6e to your computer and use it in GitHub Desktop.
Save seanbehan/994cd96a2a3febc94cb5d50f5364de6e to your computer and use it in GitHub Desktop.
get list of wordpress post tags and taxonomies
select x.taxonomy, left(t.name, 50) name, left(p.post_title, 50) post_title from
wp_terms t,
wp_term_taxonomy x,
wp_term_relationships r,
wp_posts p
where
t.term_id = x.term_id
and
x.term_taxonomy_id = r.term_taxonomy_id
and
r.object_id = p.ID
@seanbehan
Copy link
Author

With group by post title

select  x.taxonomy as taxonomy, left(p.post_title, 50) as post_title, left(group_concat(t.name, ' '), 50) as name
from
  wp_terms t,
  wp_term_taxonomy x,
  wp_term_relationships r,
  wp_posts p
where
  t.term_id = x.term_id
and
  x.term_taxonomy_id = r.term_taxonomy_id
and
  r.object_id = p.ID
group by 
 x.taxonomy, p.post_title

@seanbehan
Copy link
Author

Group by taxonomy and agg post titles

select  x.taxonomy as taxonomy, left(t.name, 50) as post_title, left(group_concat(p.post_title, ' '), 50) as name
from
  wp_terms t,
  wp_term_taxonomy x,
  wp_term_relationships r,
  wp_posts p
where
  t.term_id = x.term_id
and
  x.term_taxonomy_id = r.term_taxonomy_id
and
  r.object_id = p.ID
group by 
 x.taxonomy, t.name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment