Clear or reset the wordpress posts pagination while changing filters -
i think simple, don't it. filter:
<form class='post-filters'> <select name="filter"> <?php $filter_options = array( 'houses' => 'houses', 'hotels' => 'hotels', ); foreach( $filter_options $value => $label ) { echo "<option ".selected( $_get['filter'], $value )." value='$value'>$label</option>"; } ?> </select> <input type='submit' value='filter!'> </form>
related php apply filter wordpress query:
<?php global $destinations; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $destinations = new wp_query([ 'paged' => $paged, 'location' => $location, 'category_name' => urldecode(get_query_var('filter')), 'posts_per_page' => 6 ]); ?>
if select "filter" , result has more 6 entries, use next_posts_link()
see next 6 results. problem now, if i'm on page 2 or 3 , other filter has less e.g. 6 entries, see no results while changing filter.
how clear variable (/page/2/) while changing filter?
example:
category/subcategory/subsubcategory/page/3/?filter=houses
now select "filter" hotels
category/subcategory/subsubcategory/page/3/?filter=hotels
and "/page/3" not cleared. can not see posts.
Comments
Post a Comment