arraypress / edd-product-query
此库通过提供支持复杂过滤、排序和元查询的高级产品查询类扩展了Easy Digital Downloads (EDD)。它通过利用自定义分类和元数据操作以及暂存缓存,增强了WordPress环境中的查询功能。
Requires
- php: ^7.4 || ^8.0
This package is auto-updated.
Last update: 2024-09-18 15:39:28 UTC
README
使用高级查询功能增强您的Easy Digital Downloads插件或自定义主题。此PHP类允许您使用如分类、标签、价格范围和自定义元数据等详细参数执行复杂的产品查询。它利用WordPress的WP_Query
提供优化、可缓存的商品列表。
功能
- 高级分类过滤:使用各种组合的分类和标签来细化产品搜索。
- 支持元查询:对自定义字段和EDD属性进行复杂查询。
- 布尔标志:根据布尔值(例如产品是否可邮寄或具有可变定价)过滤产品。
- 暂存缓存:通过缓存查询结果来提高性能。
- 调试模式:输出查询参数以供分析和调试。
最低要求
- PHP 7.4
- WordPress 6.5.3
- Easy Digital Downloads 3.2.12
安装
这不是一个独立的插件,而是一个要包含在您的WordPress插件或主题中的库。
您可以使用Composer
composer require arraypress/edd-product-query
// Require the Composer autoloader to enable class autoloading. require_once __DIR__ . '/vendor/autoload.php'; use function ArrayPress\Utils\EDD\get_downloads;
用法示例
以下示例演示了如何使用get_downloads
函数根据各种标准查询EDD产品
基本用法
使用简单的分类和属性过滤器检索产品
// Use the helper function to get products with specific licensing options. $products = get_downloads( [ 'licensing' => true // Only products with licensing enabled ] ); // Retrieve all access products. $products = get_downloads( [ 'all_access' => true // Only products with all access enabled ] ); // Retrieve variable priced products. $products = get_downloads( [ 'variable' => true // Only products with variable pricing enabled ] ); // Retrieve multi-mode variable priced products. $products = get_downloads( [ 'multi' => true // Only products with multi-mode enabled ] ); // Retrieve shippable products. $products = get_downloads( [ 'shipping' => true // Only products with shipping enabled ] ); // Retrieve commissions products. $products = get_downloads( [ 'commissions' => true // Only products with commissions enabled ] ); // Retrieve commissions products. $products = get_downloads( [ 'commissions' => true // Only products with commissions enabled ] ); // Retrieve products with files. $products = get_downloads( [ 'files' => true // Only products with files ] ); // Retrieve subscription products. $products = get_downloads( [ 'recurring' => true // Only products with recurring payments enabled ] );
'files' => null, 'tax_exempt' => null, 'commissions' => null, 'licensing' => null, 'recurring' => null, 'all_access' => null, 'bundles' => null, 'service' => null, 'variable' => null, 'multi' => null, 'shipping' => null, 'type' => null,
分类过滤
此库支持所有注册的分类,并使用特定操作符来细化查询
// Query products within a single category. $products = get_downloads( [ 'category' => 'templates' // Products categorized under 'templates' ] ); // Query products belonging to multiple categories. $products = get_downloads( [ 'category' => [ 'templates', 'audio' ] // Products categorized under 'templates' or 'audio' ] ); // Exclude specific categories. $products = get_downloads( [ 'category__not_in' => [ 'freebies' ] // Products not in 'freebies' category ] ); // Products that must match all specified categories. $products = get_downloads( [ 'category__and' => [ 'templates', 'video' ] // Products must be in both 'templates' and 'video' categories ] );
数字和元字段查询
您可以直接使用数字字段和比较,而无需创建复杂的元查询
// Query products priced above a certain amount using comparison operators. $products = get_downloads( [ 'price' => 20, 'price_compare' => '>' // Products priced greater than 20 ] ); // Fetch products with a rating above a specific value. $products = get_downloads( [ 'rating' => 4, 'rating_compare' => '>=' // Products with a rating of 4 or more ] );
支持的数字比较运算符
=
: 等于!=
: 不等于>
: 大于>=
: 大于等于<
: 小于<=
: 小于等于BETWEEN
: 介于两个值之间的数组NOT BETWEEN
: 不介于两个值之间的数组
调试
启用调试以查看构建的查询参数,有助于开发和故障排除
// Debugging a query to see the SQL statement. $products = get_downloads( [ 'debug' => true, // Enable debugging 'category' => 'utilities' // Products in 'utilities' category ] );
贡献
非常欢迎对此库的贡献。在GitHub上提出问题或提交修复错误或新特性的拉取请求。分享反馈和改进建议。
许可:GPLv2或更高版本
本程序是免费软件;您可以在自由软件基金会发布的GNU通用公共许可证的条款下重新分发和/或修改它;许可证的第二版,或者(根据您的选择)任何更高版本。
本程序以希望它将是有用的目的进行分发;但是,没有任何保证;甚至没有关于适销性或特定用途的隐含保证。有关详细信息,请参阅GNU通用公共许可证。