• Pulling my hair out!!!!!

    Ok so I am setting up Pagination on a loop, something that I have done a bunch of times… more than enough, this is a simple code base that I wrote using the codex and up until now it has worked EVERY time.

    Now it is not!

    Here is the loop


    global $my_query;

    $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;

    // Arguments for the custom WP_Query
    $args = array(

    ‘posts_per_page’ => ‘5’,
    ‘paged’ => $paged,
    ‘category_name’ => ”,
    ‘type’ => ‘my_query’,
    ‘child_of’ => 0,
    ‘parent’ => ”,
    ‘orderby’ => ”,
    ‘order’ => ‘ASC’,
    ‘hide_empty’ => 1,
    ‘hierarchical’ => 1,
    ‘exclude’ => ”,
    ‘include’ => ”,
    ‘number’ => ”,
    ‘taxonomy’ => ”,
    ‘pad_counts’ => false,

    );

    $my_query = new WP_Query($args);

    ?>

    <?php if ( $my_query->have_posts() ) : ?>

    <!– the loop –>
    <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>

    and now for my pagination


    <div class=”pagination”>

    <?php
    $unliklyint = 999999999; // need an unlikely integer

    echo paginate_links( array(
    ‘base’ => str_replace( $unliklyint, ‘%#%’, esc_url( get_pagenum_link( $unliklyint ) ) ),
    ‘format’ => ‘/page/%#%’,
    ‘current’ => max( 1, get_query_var(‘paged’) ),
    ‘prev_next’ => false,
    //’prev_text’ => __(‘? Previous’),
    //’next_text’ => __(‘Next ?’),
    ‘end_size’ => ”,
    ‘mid_size’ => ”,
    ‘type’ => ”,
    ‘add_args’ => ”,
    ‘add_fragment’ => ”,
    ‘before_page_number’ => ”,
    ‘after_page_number’ => ”,
    ‘show_all’ => true,
    ‘total’ => $my_query->max_num_pages
    ) );
    ?>

    </div>

    Been at it for hours searching the web, then I tried a plugin and it did the same thing…

    Is this a bug, was something depreciated, or am I missing something, hope to hear back soon, thanks for looking.

Viewing 1 replies (of 1 total)
  • Is it possible that you need to use get_query_var(‘page’) instead of get_query_var(‘paged’)? A quote from the Codex:

    Pagination Note: Use get_query_var(‘page’); if you want your query to work in a Page template that you’ve set as your static front page.

    Here is one way to handle both cases:

    if (get_query_var('paged')) {
       $paged = get_query_var('paged');
    } elseif (get_query_var('page')) {
       $paged = get_query_var('page');
    } else {
       $paged = 1;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘WP 4 and Pagination’ is closed to new replies.