Support » Fixing WordPress » wp_query and wp-navi

  • hi, i have a custom page template that has 2 wp-querys, the first one gets the first post then the second one gets the rest of them.
    I need to add wp-page navi to the second but it seems my code is screwed, can someone help me out.

    get first post:

    $page= get_query_var('page');
    ?>
    <?php $featured = new WP_Query(
    	array(
    		'posts_per_page' => 1
    	)
    ); ?>
     <?php if ( $featured->have_posts() ) : ?>
        <?php while ( $featured->have_posts() ) : $featured->the_post(); ?>
    [my post code]
     <?php endwhile; ?>
    <?php else:  ?>
        [no posts available at this time.]
    <?php endif; ?>
            <?php wp_reset_postdata(); ?>

    then i pull the rest of the posts

    <?php $therest = new WP_Query(
        array(
           'offset' => ( $page - 1 ) * 3,
           'posts_per_page' => 3,
           'paged' => $page
        )
       ); ?>
          <?php if ( $therest->have_posts() ) : ?>
        <?php while ( $therest->have_posts() ) : $therest->the_post(); ?>
    [my post code]
     <?php endwhile; ?>
    
    <div class="navigation"><p><?php posts_nav_link(); ?></p></div>
    <?php wp_pagenavi( array( 'query' => $therest ) ); ?>
    
            <?php wp_reset_postdata(); ?>
    <?php else:  ?>
        no posts currently available.
    <?php endif; ?>

    it pull the posts but the page nav shows the same results for the first 2 pages. Im pretty sure my query is incorrect so im hoping someone can help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi andy,

    to me, you can’t make 2 calls to db on same page, unless it’s async, but even wordpress is built that way:

    1) if data to load, query database
    2) load fluff like beforehand
    3) show all html and result if a query was made in 1

    But you can’t pull 2 queries at once, it’s wordpress (rather php) built like that

    I mean by that php is mono query, so, unless i’m full wrong, you can’t call 2 databases before a page or post call

    and this is not a wordpress issue, rather lamp

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_query and wp-navi’ is closed to new replies.