WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on project that needs to have WooCommerce implemented, and there is a list of products on main page, using a original theme loop. I managed to display all posts and it's data, and now I'm encountering problems with themes pagination. It's working kinda fine - it recognises the number of items (products), calculates number of pages, and works fine for first 3 pages.

Then I found out that I have enough posts (normal blog posts, not Woo products) so the pagination is working fine for first 3 pages - which is number where normal blog post pagination would stop.

How can I fix this, so pagination goes for example to page 5, and not show me 404 error page?

Here's the loop:

                $args = array(
                    'posts_per_page' => '4',
                    'post_type' => 'product',
                    'paged' => get_query_var('paged')
                $homepage_query = new WP_Query($args);
            <?php //query_posts('posts_per_page=4&paged='.get_query_var('paged')); ?>
            <?php if ( have_posts() ) : ?>  
                <?php while ( $homepage_query->have_posts() ) : $homepage_query->the_post(); ?>
                    <?php if($style == 'blog_style') { ?>
                    <div id="blog-style" class="post-box">

                        <?php get_template_part('content', 'blog'); ?>
                    <?php } else { ?>
                    <div class="post-box proizvod-box grid_4 <?php aero_post_box_class(); ?>">

                        <?php woocommerce_get_template_part( 'content', 'product' ); ?>

                        <?php //get_template_part('content', ''); ?>
                    <?php } ?>
                <?php endwhile; wp_reset_query(); ?>

And here's the pagenavi function file: http://jsbin.com/umumeq/1/edit

share|improve this question

Try $homepage_query->have_posts() instead of have_posts() in your if condition.

share|improve this answer
No, same thing as before. But thanks for this! – jOpacic Nov 8 '12 at 9:54
Your pagenavi code is a nightmare! It's intermingling both $homepage_query and the main query, so no wonder there's conflict - you'd be much better off hooking onto (& overriding) the main query with the parse_query or pre_get_posts hook. – TheDeadMedic Nov 8 '12 at 9:58
Can you please post a short example? Would mean a lot! – jOpacic Nov 8 '12 at 10:29
That code was written when only blog posts were being displayed, and worked great. But now, problem - as you can see. – jOpacic Nov 8 '12 at 10:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.