自一个月以来,我想从完整的订单中获取产品的元数据(_wcj_purchase_price)。
我尝试使用MYSQL和WP_Query,但很快就迷失了。
实际上,我具有该产品的meta_value:
SELECT post_id as order_id, meta_key, meta_value from wp_postmeta where post_id in
( SELECT ID FROM
wp_posts
WHERE post_type = 'shop_order' and post_date BETWEEN NOW() - INTERVAL 30 DAY AND NOW()
)
and meta_key = '_wcj_purchase_price'
但是我不知道要为每种订购的产品获得此值。
答案 0 :(得分:1)
在@ dan-webb的帮助下,我得到了以下结果:
SELECT post_id as order_id, meta_key, meta_value from wp_postmeta where post_id in
( SELECT ID FROM
wp_posts
WHERE post_type = 'shop_order' and post_date BETWEEN NOW() - INTERVAL 30 DAY AND NOW()
)
and meta_key = '_wcj_purchase_price'
但是它返回的是产品元数据,而不是订购的产品。
答案 1 :(得分:0)
MySQL方式为:
SELECT post_id as order_id, meta_key, meta_value from wp_postmeta where post_id in
( SELECT ID FROM `wp_posts`
WHERE post_type = 'shop_order' and post_date BETWEEN NOW() - INTERVAL 30 DAY AND NOW()
)
and meta_key = '_wcj_purchase_price'