I think itโs easy, but I donโt understand. This is my filter:
<form class='post-filters'>
<select name="filter">
<?php
$filter_options = array(
'houses' => 'Houses',
'hotels' => 'Hotels',
);
foreach( $filter_options as $value => $label ) {
echo "<option ".selected( $_GET['filter'], $value )." value='$value'>$label</option>";
}
?>
</select>
<input type='submit' value='Filter!'>
</form>
PHP related to apply filter to wordpress request:
<?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 I select my โfilterโ and the result has more than six entries, I use next_posts_link()to view the next six results. The problem now, if I am on page 2 or 3, and the other filter is less than, for example, 6 records, I do not see any results when the filter is changed.
How to clear get (/ page / 2 /) variable when filter changes?
Example:
category/subcategory/subsubcategory/page/3/?filter=houses
Now I select the filter hotels.
category/subcategory/subsubcategory/page/3/?filter=hotels
and "/ page / 3" will not be deleted. Therefore, I do not see some messages.