Support » Fixing WordPress » Pagination at top of page for custom query

  • ssh529



    I have created a page that filters posts based on the presence of a custom field and sorts them by that custom field value. Using WP PageNavi, I have successfully implemented pagination onto this page. However, it understandably only works on the bottom of the page, because it relies on the query and the posts within.

    My question is, is there a way to get the same code at the top of the page after creating it at the bottom? I know I can’t create it at the top before the loop, but I want it to appear as if I have.

    Here is the code I am using to create the page:

    $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
    $args = array(
        'posts_per_page' => 5,
        'orderby' => meta_value,
        'meta_key' => 'Author',
    	'order' => 'ASC',
        'paged' => $paged
    $my_query = new WP_Query( $args );
    <?php if (have_posts()) : ?>
    <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>

    And, below that, my call to WP PageNavi:

    if(function_exists('wp_pagenavi')) {
    	wp_pagenavi( array(
    		'query' =>$my_query
    <?php wp_reset_postdata(); ?>

    Thank you in advance!

  • The topic ‘Pagination at top of page for custom query’ is closed to new replies.