i've created a custom loop for a custom post type in my project, that is sorted by a custom field (wether the field is filled or not).
So basically, on that archive page, all posts of that type should appear, first the ones that have the custom field with value "yes", then the ones with value "no".
This part is working as expected, however i'm struggling to make this archive page paginated, with about 8 results per page or so. i was able to get it to work to show the paging links, but all pages other than the first page show an error 404.
I've tried using some of the answers that i've found across the web, but most of them end up messing up my sorting, or showing all posts instead of only that custom type.
here is my code:
<?php $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
// get posts
$args = array(
'post_type' => 'restaurante',
'posts_per_page' => 4,
'meta_key' => 'destacado',
'orderby' => 'meta_value',
'order' => 'DESC'
);
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ): ?>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
...
<?php
$big = 999999999; // need an unlikely integer
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
) );
?>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
Can anyone please point me in the right direction?
Thanks in advance