WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] can't get value of global paged or page for pagination.

[Resolved] can't get value of global paged or page for pagination.

  • Hi! I couldn’t get the value of global paged or page to create pagination. I’ve been searching on Internet for nearly 3 hours and couldn’t figures it out.

    However if I var_dump wp_query object, it show correct information of max_page and post_count :S Please help me out. Thanks in Advanced.

    If I changed to $paged manually (example: $paged = 2), It is correctly offset the first paged.

    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' => array($men_wear, $ladie_wear),
    
                    'posts_per_page' => $limit,
    
                    'paged' =>  $paged,
    
                    'meta_key' => 'post_views_count',
    
                    'orderby' => 'meta_value'
    
                );
    
                $count = 0;
    
                $my_query = new WP_Query($args);
    
                while ($my_query->have_posts()) : $my_query->the_post();
    
                    ?>
    
                        <div class="single-product">
    
                                <a href="<?php the_permalink(); ?> ">
    
                                        <h2><?php the_title() ?> </h2>
    
                                         <?php the_post_thumbnail(); ?>
    
                                </a>
    
    				<?php if(function_exists("kk_star_ratings")) : echo kk_star_ratings($pid); endif; ?>
    
                            <?php echo ($count % 5 == 0 ) ? ' </div>' : '</div>'; ?>                       
    
                            <?php $count++; ?>                
    
                <?php endwhile; ?>
    
    	    </div>
                 <?php
                if (function_exists('wp_paginate')) {
                    wp_paginate();
                 }
                 wp_reset_query();
    
            ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator keesiemeijer

    @keesiemeijer

    On what theme template is this? Is the pagination not working?

    @keesiemeijer, I wrote them in page.php And pagination isn’t working. The main problem is I couldn’t get either paged or page value as I mentioned above. Could you kindly advise me where do I need to check those paged or page variable are set or to activate? I think it is doing automatically. isn’t it?

    Moderator keesiemeijer

    @keesiemeijer

    I think it is doing automatically. isn’t it?
    No it doesn’t. You set it to the correct page with this part:

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

    http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query

    Does wp_paginate show any pages?

    Can you try give wp_paginate() the total amount of pages [untested]:

    wp_paginate('pages=' . $my_query->max_num_pages);

    @keesiemeijer, It is working perfectly, pagination showing up now and working correctly. Why I don’t find that in Internet and even in plugin support forum 🙁 You saved my life 🙂 I’ve been looking for the solution nearly a week now and decided to get answer today as long as it take and now totally worth the decision 🙂

    could you kindly explain me why do we need to pass that parameter? I thought plugin catch them itself? isn’t it.

    Anyway, thx for the help.

    Moderator keesiemeijer

    @keesiemeijer

    Pages are not paginated by default. This plugin relies on the global $wp_query object, which still has the query object of the Page itself. To not use the default query you’ll need to give it the total amount of pages found by your custom query. I’ve looked at the plugin code some more and I think it’s best you also give it the page you’re on:

    wp_paginate('page=' . $paged . '&pages=' . $my_query->max_num_pages);

    I’m glad you’ve got it resolved 🙂

    Thx for the explanation 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] can't get value of global paged or page for pagination.’ is closed to new replies.