• Hi!

    I’m trying to paginate a custom loop that displays all comments by a specific user, but everything seems to be working properly except for the actual links to the pages which is produced by paginate_links. If I manually hard code the $page variable everything works fine.

    As an example if I click a page number it redirects to mydomain.com/3/user?=1234 (user is an existing query variable on the page)

    Ideally it would redirect to something like mydomain.com/user?=1234&page=3 but it seems to be ignoring all of the arguments I input into the paginate_links function.

    Here is my code – any help or insight would be appreciated. Thanks!:

    define(‘DEFAULT_COMMENTS_PER_PAGE’,5);
    $page = (get_query_var(‘page’)) ? get_query_var(‘page’) : 1;;
    $limit = DEFAULT_COMMENTS_PER_PAGE;
    $offset = ($page * $limit) – $limit;

    $total_comments = get_comments(array(‘orderby’ => ‘post_date’ ,
    ‘order’ => ‘DESC’,
    ‘user_id’ => $user_ID,));

    //poll the database to get all the comments by this user id
    $args = array(
    ‘user_id’ => $user_ID,
    ‘offset’=>$offset,
    ‘number’=>$limit,
    );

    $comments = get_comments($args);
    $pages = ceil(count($total_comments)/DEFAULT_COMMENTS_PER_PAGE);?>
    <div class=”profile_comments”>
    <h2>Recent Activity: </h2> <?php
    foreach($comments as $comment) : ?>
    //the code to print individual comments – not important here
    </div></div> <?php
    endforeach;
    ?> </div>
    </span>

    <?php
    $args = array(
    ‘base’ => @add_query_arg(‘page’,’%#%’),
    ‘format’ => ‘page/%#%’,
    ‘total’ => $pages,
    ‘current’ => $page,
    ‘show_all’ => False,
    ‘end_size’ => 1,
    ‘mid_size’ => 2,
    ‘prev_next’ => True,
    ‘prev_text’ => __(‘Previous’),
    ‘next_text’ => __(‘Next’),
    ‘type’ => ‘plain’);

    // ECHO THE PAGENATION
    echo paginate_links( $args );
    ?>

  • The topic ‘Problem with paginate_links’ is closed to new replies.