Support » Plugin: WP-PageNavi » Pagination and Custom Query

  • I have read numerous articles on using pagination with custom query, but I’m still unable to get my page to work properly. I know that the pagination works, but my code is wrong somewhere because when I click page 2, page 1 appears instead. Please help. My code is below. Thanks so much.

    <?php
    if(isset($_REQUEST['sort'])){
    	if($_REQUEST['sort'] == 'desc' )
    		$order = "&orderby=title&order=DESC";
    	else if($_REQUEST['sort'] == 'asc' )
    		$order = "&orderby=title&order=ASC";
    }
    
    else 
    
    $order = "&orderby=ID&order=DESC"; 
    
    ?>
    
    <form method="post" id="order">
      <select name="sort" onchange='this.form.submit()'>
        <option value="">Sort by</option>
        <option value="desc">Sort by Desc</option>
        <option value="asc">Sort by Asc</option>
      </select>
    </form>
    
    <?php $my_query = new WP_Query( array( 'cat' => 30, 'paged' => get_query_var('paged') ) . $order 
    
    ); while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    
    CONTENT IS HERE
    
    <?php endwhile; ?>
    
    <?php wp_pagenavi( array( 'query' => $my_query ) ); ?>
    
    <?php wp_reset_postdata(); ?>

    http://wordpress.org/extend/plugins/wp-pagenavi/

  • The topic ‘Pagination and Custom Query’ is closed to new replies.