如何在WooCommerce中使用SQL查询获取缩略图URL

时间:2017-05-22 07:57:35

标签: mysql wordpress phpmyadmin woocommerce

我想从SQL查询中获取缩略图URL。

我尝试了这个SQL查询:

p.ID,
  p.post_title,
  meta_value,
  t.name AS product_category,
  t.term_id AS product_id,
  t.slug AS product_slug,
  tt.term_taxonomy_id AS tt_term_taxonomia,
  tr.term_taxonomy_id AS tr_term_taxonomia,
  MAX(CASE WHEN pm1.meta_key = '_price' then pm1.meta_value ELSE NULL END) as price,
  MAX(CASE WHEN pm1.meta_key = '_regular_price' then pm1.meta_value ELSE NULL END) as regular_price,
  MAX(CASE WHEN pm1.meta_key = '_sale_price' then pm1.meta_value ELSE NULL END) as sale_price,
  MAX(CASE WHEN pm1.meta_key = '_wp_attached_file' then pm1.meta_value ELSE NULL END) as image
FROM wp_posts p 
LEFT JOIN wp_postmeta pm1 ON pm1.post_id = p.ID
LEFT JOIN wp_term_relationships AS tr ON tr.object_id = p.ID
JOIN wp_term_taxonomy AS tt ON tt.taxonomy = 'product_cat' AND tt.term_taxonomy_id = tr.term_taxonomy_id 
JOIN wp_terms AS t ON t.term_id = tt.term_id
WHERE p.post_type in('product', 'product_variation') AND p.post_status = 'publish'
GROUP BY p.ID,p.post_title;

但它没有显示出理想的结果。

1 个答案:

答案 0 :(得分:0)

使用自定义字段插件。

然后创建字段和链接发布此插件非常容易和快速的性能。