这是基于 WordPress 和 WooCommerce 并处理 post 和 post_meta 表
我必须获取所有具有meta_key =“_shop”和meta_value =“yes”的产品ID
典型条件:
如果元键和元值与父产品匹配,则其所有变体也必须包括。
如果元键和元值未与父级一起行进,但其变体具有元键和元值匹配,则仅返回变体。
Product(#18)(simple): _shop = 'yes'
Product(#19)(variable): _shop = 'yes' (Parent is Yes)
Product(#20)(variation): _shop = 'yes'
Product(#21)(variation): _shop = 'no'
Product(#22)(variation): _shop = 'no'
Product(#23)(simple): _shop = 'yes'
Product(#24)(variable): _shop = 'no' (parent is no)
Product(#25)(variation): _shop = 'no'
Product(#26)(variation): _shop = 'yes' (Only this variation)
Product(#20)(variation): _shop = 'no'
我需要的 IDS:
#18 #19 #20 #21 #22 #23 #26
最佳答案
select productID from your_table
where meta_key = "_shop" and meta_value = "yes"
关于mysql - Woocommerce 通过自定义查询获取产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51375919/