mysql - Woocommerce 通过自定义查询获取产品

标签 mysql wordpress woocommerce

这是基于 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/

相关文章:

mysql - sql根据用户对话显示未读消息

wordpress - WP 页面模板中硬写的内容是否可以被搜索引擎索引?

wordpress - 从 Wordpress 管理员中删除事件提要

php - 在 Woocommerce 中的电子邮件订单总计表中插入自定义字段值作为新行

php - 将 iOS 设备 token 存储到 MySQL 数据库

php - 提交表单时在 Laravel 中路由

WordPress 元查询键数组

php - 移动产品描述 Div Woocommerce

php - Woocommerce 购物车页面添加额外的 <p> 标签

php - PHP格式化类的设计以及提高性能和速度