I’m using WordPress with WooCommerce and I have written the following SQL query which gets the product category terms IDs names and slugs:
SELECT t.term_id AS id, t.name AS post_title,t.slug AS post_url
FROM wp_terms t
LEFT JOIN wp_term_taxonomy tt ON t.term_id = tt.term_id
WHERE tt.taxonomy = 'product_cat'
ORDER BY name
How should I change this SQL query to get also the product category thumbnail Id?
Note: I’m only interested in a SQL query, but not anything else like a WP_Query.
2
Answers
Instead of rely on MySQL query my suggestion is please look into the REST API provided by WooCommerce.
For your need the good candidate is
Get Category API service
Which have the details which you expect like this
For multiple categories
List all product categories
Sample output will be like this:
On
All product categories
API please check available parameters some of the important parameters are:To get additionally the thumbnail ID in your SQL query for WooCommerce product category terms, you can use the following instead:
Tested and works.