Custom post types on page with filter and pagination

How to apply pagination to the filtered results when filter adds the string
‘?filtr=1’ after the domain name ?

The filter works the following way…
On my website (http://arche.cypis.net.pl/) after clicking ‘NAZWA’ filter in header I get the filtered results which output ‘project custom posts’ in alphabetic order, but I can’t work out
how to make it work with pagination because after clicking pagination links I get werid URL’s

My attempt is following:

if ($_GET[“filtr”] == 1) {

$args = array(
‘post_type’ => array(‘projekt’), // Posts
‘orderby’ => ‘title’,
‘order’ => ‘ASC’,
‘posts_per_page’ => 8, // get all posts
‘ignore_sticky_posts’ => true, // Do not preserve order of stickies
);
$paged = (get_query_var(‘page’)) ? get_query_var(‘page’) : 1;
$the_query = new WP_Query( $args );

echo ‘<div class=”home-pagination”>’;
echo paginate_links(array(
‘base’ => get_pagenum_link(1) . ‘%_%’,
‘format’ => ‘page/%#%’,
‘current’ => max(1, get_query_var(‘page’)),
‘total’ => $the_query->max_num_pages,
‘prev_text’ => __(‘” poprzedni’),
‘next_text’ => __(‘następny »’),
‘page’ => $paged,
“enable_filter” => ‘title’
));
echo ‘</div>’;
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<div class=”col-lg-3 col-sm-6 col-md-4 project-list”>
<div class=””>
<a href=”<?php the_permalink(); ?>”>
<div class=”img-crop”>
<?php
$image = get_field(‘glowny_obraz’);
$size = ‘wordpress-800-500’;
$thumb = $image[‘sizes’][ $size ];
$width = $image[‘sizes’][ $size . ‘-width’ ];
$height = $image[‘sizes’][ $size . ‘-height’ ];
if (!empty($image)):
?>
<img src=”<?php echo $thumb; ?>” alt=”<?php echo $image[‘alt’]; ?>” />
<?php endif; ?>
</div>
<div class=”border-description”>
<div class=”col-lg-7 col-md-7 col-sm-7 col-xs-7″>
<p class=”title”><?php the_title(); ?> </p>
</div>
<div class=”col-lg-5 col-md-5 col-sm-5 col-xs-5″>
<p class=”description”><?php echo str_replace(‘.’, ‘,’, get_field(‘powierzchnia_uzytkowa’));?>m<sup>2</sup></p>
</div>
</div>
</a>
</div>
</div>

<?php endwhile; wp_reset_query();

}

Read more here:: Custom post types on page with filter and pagination

Leave a Reply

Your email address will not be published. Required fields are marked *