i have following page where i filter posts based on their category. This filter works fine, but if there are multiple pages of filtered results and i click to go to page 2 the filter resets and shows every post again instead of page 2 of the filtered results. How can i go to the second page of the filtered results?
Code:
<form class="form-inline" method="POST" action="/intranet/bibliotheek/">
<?php $intranetCategorie = get_terms( 'intranet_categorie');
if (!empty($intranetCategorie) && !is_wp_error($intranetCategorie )) {
echo '<select class="form-control training-drop" name="intranetCategorie">';
echo '<option value="empty">Alle Items</option>';
foreach ($intranetCategorie as $terms) {
if(0 != $terms->parent ){
echo '<option value="'. $terms->slug .'">' .$terms->name.'</option>';
}
}
echo '</select>';
}
?>
<input class="btn btn-intra" type="submit" value="Filter Resultaten">
</form>
<?php foreach ($intranetCategorie as $terms) {
$categorie[] = $terms->slug;
}
if(isset($_POST['intranetCategorie']) && $_POST['intranetCategorie'] != 'empty'):
$categorie = $_POST['intranetCategorie'];
endif;
?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'intranet',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'intranet_categorie',
'field' => 'slug',
'terms' => 'bibliotheek',
),
array(
'taxonomy' => 'intranet_categorie',
'field' => 'slug',
'terms' => $categorie,
),
),
'posts_per_page' => 5,
'paged' => $paged
);
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h3 class="intranet-title"><?php the_title(); ?></h3>
<p class="post-info">Geplaatst op <?php the_time('j F Y'); ?></p>
<p><?php the_content(); ?></p>
<?php
$file = get_field('upload');
if (!empty($file)) {
if( $file ):
// vars
$url = $file['url'];
$title = $file['title'];
$caption = $file['caption'];
// icon
$icon = $file['icon'];
if( $file['type'] == 'image' ) {
$icon = $file['sizes']['thumbnail'];
}
if( $caption ): ?>
<div class="wp-caption">
<?php endif; ?>
<a href="<?php echo $url; ?>" title="<?php echo $title; ?>" target="_blank">
<img src="<?php echo $icon; ?>" />
<span><?php echo $title; ?></span>
</a>
<?php if( $caption ): ?>
<p class="wp-caption-text"><?php echo $caption; ?></p>
</div>
<?php endif; ?>
<?php endif; ?>
<?php } ?>
<?php if ( 'post' == get_post_type() ) : ?>
<footer class="edit">
<?php edit_post_link( __( 'Bewerk', 'soml' ), '<span class="glyphicon glyphicon-pencil"> ', '</span>' ); ?>
</footer><!-- .entry-footer -->
<?php else : ?>
<?php edit_post_link( __( 'Bewerk', 'soml' ), '<footer class="entry-footer"><span class="glyphicon glyphicon-pencil"> ', '</span></footer><!-- .entry-footer -->' ); ?>
<?php endif; ?>
<hr>
<?php endwhile; ?>
<div class="pagination-links-intranet">
<?php
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages,
'prev_text' => '« Vorige',
'next_text' => 'Volgende »'
) );
?>
</div>
<?php else : ?>
<?php echo'<p>Er zijn geen berichten gevonden</p>' ?>
<?php endif; ?>
Pagination after i filter on a category (working as intended):
Pagination after i select page 2 of the filtered results:
The filter resets and will show all posts again. It should go to the second page of the filtered results.
Switching $_POST to $_GET will fix the problem since $_POST doesn’t carry over when switching pages.