WordPress.org

Ready to get started?Download WordPress

Forums

WP-Paginate
Incorrect Number of Pages with Custom Post Type (1 post)

  1. perryazevedo
    Member
    Posted 8 months ago #

    Trying to figure out what is wrong with my code. I'm using WP_Query to loop through a custom post type called "Event." I'm also limiting the posts to only those with a date newer than today, using a custom field. Finally, I'm using the WP Paginate plugin for pagination.

    I'm getting the correct number of posts to show up. However, the pagination plugin is showing a total of 5 pages, no matter how little or how many posts are being pulled in through the loop.

    Any help would be very appreciated.

    $today = date('Ymd');
    $args = array(
        'post_type' => 'event',
        'posts_per_page' => 5,
        'meta_key' => 'event_date',
        'meta_compare' => '>',
        'meta_value' => $today,
        'orderby' => 'event_date',
        'order' => 'ASC',
        'paged' => $paged
    );
    $event_post = new WP_Query($args);
    if ( $event_post->have_posts() ) {
        // The loop
        while ( $event_post->have_posts() ) {
            $event_post->the_post();
    
            // The Content
    
        }
        // End of the loop
    
        if(function_exists('wp_paginate')) { wp_paginate(); }
    
    } else {
        // no posts found
    }
    wp_reset_postdata();

    http://wordpress.org/plugins/wp-paginate/

Reply

You must log in to post.

About this Plugin

About this Topic