I am working directly with MySQL, using MySQL workbench. Can you help me write a SQL query that will pull all custom taxonomies and their term-meta fields?

I have a custom taxonomy called(slug) census-tract

and a few custom fields attached to each:

census-tract-income-level census-tract-population

How would I go about joining the following tables


to find WHERE wp_termmeta.meta_key = 'census-tract-population' AND wp_termmeta.meta_key = 'census-tract-income-level' ?


  • do you want the taxonomies or the terms, along with the termmeta, and do you want all, or just the one you mentioned?
    – inarilo
    Jun 10, 2017 at 21:15
  • Just the one taxonomy I mentioned along with all of it's termmeta. Jun 10, 2017 at 21:17
  • but term meta is term specific, not taxonomy specific
    – inarilo
    Jun 10, 2017 at 21:24
  • Ah, gotcha. I'm a little fuzzy with how the relationship/hierarchy goes. So let's try this again, SQL for .... just the one taxonomy for all of it's terms and each term's termmeta. Jun 10, 2017 at 21:31

1 Answer 1



select t.name, t.slug, tm.meta_key, tm.meta_value
from wp_term_taxonomy AS tt
inner join wp_terms AS t ON tt.term_id = t.term_id
inner join wp_termmeta AS tm ON t.term_id = tm.term_id
where tt.taxonomy = 'census-tract'
order by t.name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.