0
votes

I have make a simple wpquery for get all events. Then with an "if" condition I check if the event start today and if yes, show the title post. My problem is with pagination, because i don't know make a pagination based on the loop result.

 if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
 elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
 else { $paged = 1; }

 $args = array(
'post_type' => 'events',
'posts_per_page' => '5',
'order' => 'ASC',
'paged' => $paged   
 );

 query_posts($args); 

if ( have_posts() ) while ( have_posts() ) : the_post();
    $event_start = get('event_start');

    // if the event start is today show the title post
    if($event_start == date('d.m.Y')){
       the_title();
    }
endwhile;
// PROBLEM: show the pagination for all events
wp_pagenavi();
1

1 Answers

0
votes

I would use a WP_Query and use the custom field parameters to only pull the relevant results. This way pagination will work directly and you won't be retrieving and looping over posts that are not required.

As a side note, you may also find this answer useful as to why you shouldn't use query_posts.