我是 PHP 和 WordPress 的新手。我使用了 2 個下拉列表,一個用于過濾類別,另一個用于按目的排序。對于排序和過濾,我沒有使用任何鉤子。以下用于 filter 和 sortby 實(shí)現(xiàn)的代碼以及我用于 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() 但由于沒有鉤子而無法獲得任何運(yùn)氣。有什么辦法嗎?
1 回答

呼啦一陣風(fēng)
TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超6個贊
我沒有看到您的“清除過濾器”按鈕,也沒有看到您問題中的第二個選擇,但是如何使用以下內(nèi)容:
<button onclick="clearFilters()">CLEAR FILTERS</button>
然后在您的 .js 或內(nèi)聯(lián)腳本中
function clearFilters(){
jQuery('#selcategories').val('all');
jQuery('#sortbyFilter').val('all');
}
- 1 回答
- 0 關(guān)注
- 172 瀏覽
添加回答
舉報
0/150
提交
取消