• Resolved wannes

    (@wannes)


    First of all I apologize if this is not the correct place to post this question.

    I got a site with some funky reacting pagination. I use the pagination like so :

    <?php
    
    $big = 999999999; // need an unlikely integer
    
    $totaal = wp_count_posts();
    
    $pagination = paginate_links( array(
    	'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    	'format' => '?paged=%#%',
    	'current' => $paged,
    	'total' => $wp_query->max_num_pages,
    	'type'=> 'aray',
    ) );
    
    print_r($pagination);
    	wp_reset_postdata();
    
    ?>

    This gives me 286 pages, but with 6 item on each page and 879 posts the number ofpages is incorrect. If i leave this on and go to page 7, nothing is displayed. Only the pages up til 6 work as they should. If I switch $wp_query with $home_query ( $home_query = new WP_Query( $args ) ) in ‘total’, then I only get 6 pages.

    So somewhere ( probably in a bit of code that I didn’t post ) I tell wordpress to only add functionality to 6 pages or something like that. Does anyone know how to fix this or in what section of all my code the problem could be ? The link to the website is

    Thank you in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I noticed you have a typo in the ‘type’. I believe it should be ‘array’.

    Thread Starter wannes

    (@wannes)

    Yeah, I noticed that to. Using ‘array’ gives me a key and a value for each page, while using ‘aray’ gives the same result as using ‘plain’. At first I thought it had something to do with the number of posts per page. I show 6 posts per page and only 6 pages work. I increased the number of posts per page and in any case it only shows 36 posts. I’m not really sure where in the code I’m forgetting something and posting the whole code might be overkill.

    [EDIT]
    I found the problem, for some reason the following code messed everything up

    $last_posts = wp_get_recent_posts($args);
    	foreach( $last_posts as $last_post ){
    		$last_post_issue_number = esc_html(get_post_meta($last_post[ID], '_issue_number', true));
    	}

    Could someone tell me exactly what this piece of code does ( I only have a general idea ) ? After that I can close down this thread.

    Moderator bcworkz

    (@bcworkz)

    Out of context, it doesn’t really do anything meaningful, although wp_get_recent_posts() does call get_posts() which in turn creates a new WP_Query($args). Since $query->the_post() is never called here, there should be no need to reset the post data, yet this sounds like this is the likely cause of your problem. Without seeing the entire code sequence, it’s difficult to say.

    If you don’t find this explanation satisfactory, you could post the whole sequence at pastebin.com and simply place a link here. Maybe it’ll result in a better explanation.

    I say it doesn’t do anything meaningful because the subsequent loop gets a post meta value for each recent post and assigns it to $last_post_issue_number, but nothing is done with the value. It is simply overwritten in the next loop, unused. Maybe once the loop completes something is done with the final value, but that would be an odd way to deal with getting a final value.

    Thread Starter wannes

    (@wannes)

    Putting that piece of code in comment fixed my problem, so I don’t believe there’s a reason to post more code ??

    I didn’t write the code myself, so thank you bcworkz for explaining it to me.

    Consider this post resolved (yey!)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Pagination problem’ is closed to new replies.