• Hi there

    I have a little problem with my category navigation and I guess it has something to do with wp_query. I read several threads about this, but nothing got my problem solved.

    Could somedbody be so nice and take a look at my code? I get 404 and /category/produkte/page/2 shows the index.php.

    Thanks!

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Did you setup a custom permalink structure?

    Also, if you are using multiple queries on one template page you need to make sure you use wp_reset_postdata() or wp_reset_query depending on your situation.

    Thread Starter mac800

    (@mac800)

    Not really a custom permalink just /%postname%/.

    I am using multiple queries and I tried your suggestion to use wp_reset_postdata() and wp_reset_query, but it didn’t work.

    I’m closing with this…

    <?php endwhile; ?>
    <div id="navigation" class="digital_f"><?php posts_nav_link(); ?></div>
    <?php $wp_query = null;
          $wp_query = $temp;
          wp_reset_query();
    ?>
    Thread Starter mac800

    (@mac800)

    I tried something and right now it shows at least ten of my posts though (5 on each page (‘posts_per_page’ => 5)) there are 21.

    <?php
    $original_query = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query( array('posts_per_page' => 5, 'post_type' => 'produkt', 'paged' => $paged) );
    if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

    Any idea why it limits itself to 10 posts instead of showing all 21?

    I would use the wp_pagenavi plugin to page your posts – so much easier. I’m also not sure why you are setting wp_query to null, that’s not necessary. You just need to call wp_reset_query() after your loop.

    If you are using wp_pagenavi, your query args should look like this:


    $args=array(
    'post_type' => 'post',
    'order'=> 'DESC',
    'post_status' => 'publish',
    'posts_per_page' => 6,
    'paged' => get_query_var('paged'),
    'caller_get_posts'=> 1
    );

    The call to WP_Query & loop looks like this:

    <?php $my_query = new WP_Query($args); ?>
    <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>

    The pagenavi call looks like this:

    <?php wp_pagenavi(array( 'query' => $my_query ) ); ?>

    Thread Starter mac800

    (@mac800)

    Thanks for the code, hobbsh. I installed wp_pagenavi but unfortunately it didn’t work. This is how I used your code…

    $args=array(
    'post_type' => 'product',
    'order'=> 'DESC',
    'post_status' => 'publish',
    'posts_per_page' => 20,
    'paged' => get_query_var('paged'),
    'caller_get_posts'=> 1
    );
    $my_query = new WP_Query($args);
    while ( $my_query->have_posts() ) : $my_query->the_post(); ?>

    And I close like this…

    <?php endwhile; ?>
    <?php wp_pagenavi(array( 'query' => $my_query ) ); ?>

    Pagenavi seems to work, Pagination buttons are changing when I change posts_per_page value.

    Still it returns 404, when I hint the second page link.

    Any other idea?

    What’s your site url? There is probably an issue with your permalink structure I’m guessing.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Category Navigation: WP_Query Problem?’ is closed to new replies.