获取参数是查询字符串,并在wp查询中使用它们,还对过滤器使用了tax和meta查询 需要使用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;
只需要按功能排序或按顺序排序