最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

mysql - Query product's image path by category WooCommerce database?

programmeradmin0浏览0评论

I am writing a small query to grab image path and object ID from Woo_Commerce database. I am join taxonomy and relationship table to achieve this but somehow I am making mistake I can't realize. I have my category comparison set and path is coming from post_meta but somehow not giving the two columns. The category that I am intersted is just the term_ID that I want to pass (16). So I want all object ID that has term_ID 16 and the second column is their image path.

Object ID | ImgPath

SELECT 
object_id as productID, 
meta_value as imgPath

FROM wp_term_relationships as wp_re
INNER JOIN wp_postmeta as pthGiver
INNER JOIN wp_term_taxonomy as termIDgiver
on wp_re.object_id = pthGiver.post_id AND
pthGiver.meta_key = '_wp_attached_file'
WHERE termIDgiver.`term_taxonomy_id` = '16' 

As you can see in the following image WordPress is grabbing all the products and their images by category I want term_taxonomy_id = '16' which is diamond. How is WordPress filtering?

发布评论

评论列表(0)

  1. 暂无评论