• I’m using WP_Query to query a custom post type on a template page. My pagination is showing and appears to be correct but I get the same results on each page. When I check the Query being run the LIMIT start value is not changing.

    Template code

    $args = array (
    	'post_type'	=> 'event',
    	'pagination'	=> true,
    	'order'		=> 'DESC',
    );
    
    global $wp_query;
    $wp_query = new WP_Query( $args ); 
    
    if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();
    	// Get content
    	endwhile;
    	pagination();
    else :
    	// Not found
    endif;

    URL format
    http://localhost/wp-test-site/page-name/page/3/

    Query generated
    SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'event' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 2

Viewing 6 replies - 1 through 6 (of 6 total)
  • from what I undersrtand wp-Query doesn’t work with static pages

    see below

    http://wordpress.org/support/topic/wp_query-with-pages?replies=5

    wp-Query doesn’t work with static pages

    Yes it does!

    @benners_: Where did you get that pagination parameter from?

    Thread Starter benners_

    (@benners_)

    I’ve made an error thinking pagination() was a WP function as I found what I thought was a reference for it https://codex.wordpress.org/Pagination

    This is the function from the parent theme I’m using.

    function pagination($pages = '', $range = 4) {
    		$showitems = ($range * 2)+1;
    
    		global $paged;
    		if(empty($paged)) $paged = 1;
    
    		if($pages == '') {
    			global $wp_query;
    			$pages = $wp_query->max_num_pages;
    			if(!$pages) {
    				$pages = 1;
    			}
    		}
    
    		if(1 != $pages) {
    			echo "<span class='allpages'>" . __('Page', 'minti') . " ".$paged." " . __('of', 'minti') . " ".$pages."</span>";
    			if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; " . __('First', 'minti') . "</a>";
    			if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; " . __('Previous', 'minti') . "</a>";
    
    			for ($i=1; $i <= $pages; $i++) {
    				if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
    					echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
    				}
    			}
    
    			if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">" . __('Next', 'minti') . " &rsaquo;</a>";
    			if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>" . __('Last', 'minti') . " &raquo;</a>";
    		}
    	}

    You cannot pass that custom function as a parameter to WP_Query.

    I’m sorry but as you are using a commercial theme, you need to seek support from the theme’s developer/vendor. We do not support commercial products here.
    Try http://mintithemes.com/forums/

    Thread Starter benners_

    (@benners_)

    OK, thanks for trying to assist. Will try Mintithemes Forum.

    Thread Starter benners_

    (@benners_)

    In case this helps anyone, the problem was I didn’t include the ‘paged’ parameter and had nothing to do with the custom pagination function I was using.

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array (
    	'post_type'	=> 'event',
    	'pagination'	=> true,
    	'paged'         => $paged,
    	'order'		=> 'DESC',
    );
    
    global $wp_query;
    $wp_query = new WP_Query( $args ); 
    
    if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();
    	// Get content
    	endwhile;
    	pagination();
    else :
    	// Not found
    endif;
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Pagination Showing Same Records on Each Page’ is closed to new replies.