Reputation: 1
I'm having an issue with pagination on my site. I created an event list and for past events, I added the same pagination code that's in the category.php file. This is unfortunately outputting the list of past events several times on each page (like the same events listed 6 times on page 1, then the remaining events listed on the second page 6 times). What's wrong with my code?
Here you can see the problem: http://www.mybeatfix-new.com
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('paged='.$paged.'&cat='.$cat); ?>
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<?php
$eventquery = array (
'post_type' => 'events',
'orderby' => '_cmb_event-date',
'order' => 'desc',
'posts_per_page' => 5,
'meta_value' => time(),
'meta_key' => '_cmb_event-date',
'meta_compare' => '<',
'paged' => $paged,
);
?>
<?php $myeventlist = new WP_Query($eventquery); ?>
<?php while ($myeventlist->have_posts()) : $myeventlist->the_post();
$data_event = get_post_meta($post->ID, '_cmb_event-date', true);
$pretty_date = date('D M j Y', $data_event);
$m_day = get_post_meta( $post->ID, '_cmb_e_day', true );
$m_start_time = get_post_meta( $post->ID, '_cmb_e_start_time', true );
$m_end_time = get_post_meta( $post->ID, '_cmb_e_end_time', true );
$m_venue = get_post_meta( $post->ID, '_cmb_e_venue', true );
$event_text = get_post_meta($post->ID, "_cmb_e_details", true);
$event_price = get_post_meta( $post->ID, '_cmb_e_price', true );
$event_ticket_status = get_post_meta( $post->ID, '_cmb_e_ticket_status', true );
$thumbnail = get_the_post_thumbnail($id, 'event-image');
?>
<div class="elist-single">
<div class="elist-thumb">
<a href="<?php the_permalink() ?>"><?php echo $thumbnail; ?></a></div>
<div class="elist-right">
<div class="elist-title">
<a href="<?php the_permalink() ?>"><?php echo ShortenText(get_the_title()); ?></a>
</div>
<div class="elist-date"><?php echo $pretty_date; ?> </div><br />
<div class="elist-info">
<i class="icon-home"> <?php echo $m_venue; ?> </i><br />
<i class="icon-time"> <?php echo $m_start_time; ?> - <?php echo $m_end_time; ?></i><br />
<?php echo $event_price ?><br />
</div><br />
</div>
</div>
<?php endwhile;?>
<?php endwhile; endif;?>
<?php wp_link_pages(); ?>
<?php get_template_part ('inc/pagination');?>
Upvotes: 0
Views: 1145
Reputation: 215
Basically you have created a loop within a loop. You are saying while you have posts loop through all the posts so it is doing so 6 times presumably because you have 6 posts.
If you use two loops you need to <?php endwhile;?>
after the first loop and to wp_reset_postdata();
after WP_Query()
but you should be able do it in one. WP_Query
should give you all the information you need on its own complete with pagination.
For reference : WP Query
Upvotes: 1