Answer the question
In order to leave comments, you need to log in
How to get multiple values using JOIN?
Greetings. I am writing a query with handles to extract WooCommerce products and link them to categories, but I ran into a problem.
I have the following query against the WordPress database:
SELECT
wp.`ID`,
wp.`post_title` as title,
wp.`post_name` as slug,
wtr.`term_taxonomy_id` as category,
wt.`name` as category_name
FROM `wp_posts` as wp
INNER JOIN `wp_term_relationships` as wtr
ON wp.ID = wtr.object_id
INNER JOIN `wp_terms` as wt
ON wt.`term_id` = wtr.`term_taxonomy_id`
WHERE
`post_type` = 'product' AND
`post_status` = 'publish'
Answer the question
In order to leave comments, you need to log in
LEFT JOIN `wp_terms` as wt
ON wt.`term_id` = wtr.`term_taxonomy_id`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question