我是 PHP 和 WordPress 的新手。我使用了 2 个下拉列表,一个用于过滤类别,另一个用于按目的排序。对于排序和过滤,我没有使用任何钩子。以下用于 filter 和 sortby 实现的代码以及我用于 dropdown 的另一个代码片段:
if($categoryFilter && $categoryFilter == 'all' && $searchKey == '' ) {
$order = 'DESC';
if($sortbyFilter == 'best_match') $order = 'ASC';
$args = array(
'post_type' => array('auction-detail','lot','asset'),
'post_status' => 'publish',
'orderby' => 'date',
'order' => $order,
'posts_per_page' => 10,
'paged' => $paged
);
query_posts( $args );
}
if($categoryFilter && $categoryFilter != 'all' && $searchKey == '' ) {
$sortbyFilter = 'newly_listed';
$_POST['sortby-filter'] = $sortbyFilter;
$args = array(
'post_type' => array('lot','asset'),
'post_status' => 'publish',
//'orderby' => 'post_title',
//'order' => 'ASC',
'posts_per_page' => 10,
'paged' => $paged,
'tax_query' => array(
array(
'field' => 'slug',
'terms' => $categoryFilter,
'taxonomy' => 'category'
)
)
);
query_posts( $args );
}
<div class="filterCols category">
<select id="selcategories" name="category" onchange="handleChange()">
<option value='all' <?php echo (isset($categoryFilter) && $categoryFilter
== 'all') ? 'selected="selected"' : ''; ?>>All</option>
<option value='commercial_trucks' <?php echo (isset($categoryFilter) &&
$categoryFilter == 'commercial_trucks') ? 'selected="selected"' : ''; ?
>>Heavy Machinary</option>
<option value='farm_machinery_implements' <?php echo
(isset($categoryFilter) && $categoryFilter ==
'farm_machinery_implements') ? 'selected="selected"' : ''; ?>>Farm
我尝试过使用 remove_all_filters() 但由于没有钩子而无法获得任何运气。有什么办法吗?
呼啦一阵风