php - woocommerce 产品的自定义 WP 查询
问题描述
获取参数是查询字符串并在 wp 查询中使用它们,还使用税和元查询过滤器需要创建排序方式:使用 wp 查询的流行、日期和价格我在查询字符串中得到所有内容,所以很困惑我应该如何排序或排序使用查询字符串
if($starting_amount || $ending_amount || $animal || $activity || $hunting_method || $arrival_date || $departure_date || $product_cat || $orderby):
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'order' => 'DESC',
'orderby' => 'meta_value',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'animal',
'terms' => $animal,
'field' => 'id',
'include_children' => true,
'operator' => ($animal != '') ? 'IN' : 'NOT IN',
),
array(
'taxonomy' => 'activity',
'terms' => $activity,
'field' => 'id',
'include_children' => true,
'operator' => ($activity != '') ? 'IN' : 'NOT IN',
),
array(
'taxonomy' => 'hunting-method',
'terms' => $hunting_method,
'field' => 'id',
'include_children' => true,
'operator' => ($hunting_method != '') ? 'IN' : 'NOT IN',
),
array(
'taxonomy' => 'product_cat',
'terms' => $product_cat,
'field' => 'slug',
'include_children' => true,
'operator' => ($product_cat != '') ? 'IN' : 'NOT IN',
),
),
'meta_query' => array(
'relation' => 'OR',
array(
'key' => '_price',
'value' => array($starting_amount, $ending_amount),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
),
array(
'key' => 'total_sales',
'value' => array($starting_amount, $ending_amount),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
),
array(
'relation' => 'OR',
array(
'key' => 'arrival_date',
'value' => $new_arrival_date,
'meta_compare'=> ($arrival_date != '') ? '==' : '>=',
'type'=>'DATE',
),
array(
'key' => 'departure_date',
'value' => $new_departure_date,
'meta_compare'=> ($departure_date != '') ? '==' : '>=',
'type'=>'DATE',
)
)
),
'orderby' => 'date',
'posts_per_page' => -1,
);
else:
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'order' => 'DESC',
'orderby' => 'date',
'posts_per_page' => -1,
);
endif;
只需要按功能排序或排序
解决方案
推荐阅读
- dialogflow-es - 格式错误的响应:由于语音响应为空,无法将 Dialogflow 响应解析为 AppResponse
- web2py - web2py的routes.py中routes_out字典的目的是什么?
- php - 在 index.php 中渲染另一个布局
- keras - 如何使用 LSTM 进行文本分类
- oracle - 使用 oracle 数据库对 Spring Boot 应用程序进行 Dockerizing
- ios - 如何在条形顶部显示条形值?
- java - 要打印的数组的非相邻元素的最大总和
- java - 如何从 Java 中的超类访问子类?
- postgresql - Concatenate result of a SELECT into an EXECUTE
- date - 在赛普拉斯的日期输入上按 Enter