I have a custom-post-type for events and use the normal archive.php
template to list all previous events.
The thing is that I use a custom query for my event-post-type inside archive.php
like this …
<?php
if ( is_post_type_archive('wr_event') ) :
get_event_list( false, 'DSC' );
else:
rewind_posts();
get_template_part( 'inc/posts' );
endif;
?>
The function get_event_list()
looks like this …
function get_event_list( $latest = true, $order = 'ASC' ) {
echo '<ul class="event-items">';
$yesterday = time() - 24*60*60;
$compare = $latest ? '>' : '<';
$args = array(
'post_type' => 'wr_event',
'posts_per_page' => 'posts_per_page' => is_archive() ? 16 : -1,
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => $order,
'meta_value' => $yesterday,
'meta_compare' => $compare
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
get_template_part( 'inc/event', 'item' );
endwhile;
wp_reset_postdata();
echo '</ul>';
}
I'm using the same function get_event_list()
in my index.php
to list all events - and on my index I want to list ALL of them. That's why I have posts_per_page => -1
.
In my archives.php
where I want to use the same template I want however only 16 "events" to be listed and a pagination underneath.
I have the following function in my functions.php
that does work fine in my search-template. But it doesn't for this custom-archive.
function get_pagination_links( $type = 'plain', $endsize = 1, $midsize = 1 ) {
global $wp_query, $wp_rewrite;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
// Sanitize input argument values
if ( ! in_array( $type, array( 'plain', 'list', 'array' ) ) ) $type = 'plain';
$endsize = (int) $endsize;
$midsize = (int) $midsize;
// Setup argument array for paginate_links()
$pagination = array(
'base' => @add_query_arg('paged','%#%'),
'total' => $wp_query->max_num_pages,
'current' => $current,
'show_all' => false,
'end_size' => $endsize,
'mid_size' => $midsize,
'type' => $type,
'prev_next' => false
);
return paginate_links( $pagination );
}
The pagination shows up underneath my events and only 16 events are listed. However, if I click on page two, the same list of the first 16 events is listed.
Any ideas how to make that pagination work with my custom-post-type archive?