Skip to:
Content
Pages
Categories
Search
Top
Bottom

Pagination Not Working on Any Forum Page


  • skystover
    Participant

    @skystover

    Hello there,

    I am using WordPress version 6.5 and bbPress version 2.6.9. This problem has been persisting for us for a while and isn’t an issue with the latest version of WP.

    The pagination on our forums is not working. Clicking page 2 on the home page of the forum takes you to the page 2 URL but displays the results from page 1. The same thing happens if you view a topic – it shows only the most recent replies, even when going to page 2, 3, and so on.

    Our forums are at https://pharmapreneuracademy.com/groups/the-academy-forum/forum/ but are hidden. Please let us know how we can provide credentials.

    What I have tried:

    – Checked error logs both in the site back-end and in the console and did not see anything relevant.
    – Flushed & disabled the cache
    – I disabled all plug-ins and changed the theme to default. This did not fix the issue. This means it isn’t a plug-in/theme conflict.
    – Added custom post types to the cache exception rules
    – Flushed the permalinks
    – Deleted the .htaccess file manually and allowed it to regenerate.
    – “Resetting forum slugs to default” in BBpress Forum Tools.

    Can you please advise on what the issue might be?

    Thanks,
    Sky

Viewing 5 replies - 1 through 5 (of 5 total)

  • Robin W
    Moderator

    @robin-w

    what is set in

    dashboard>setting>forums>Topics and Replies Per Page

    for topics and replies


    skystover
    Participant

    @skystover

    Hey there Robin,

    Thank you for getting back to me so quickly.

    It looks like the setting in “dashboard>setting>forums>Topics and Replies Per Page” is currently set to 15/15.

    Thanks!
    Sky


    Robin W
    Moderator

    @robin-w

    contact me via

    Contact me

    with a link to this thread


    George
    Participant

    @quantum_leap

    For anyone that landed here from a Google search. The pagination is not working for forums set up inside BuddyPress groups. You need to copy those two files from
    \plugins\bbpress\templates\default\bbpress
    pagination-topics.php
    pagination-replies.php

    and copy them to
    \wp-content\themes\[yourchildtheme]\bbpress

    Replace the code inside pagination-topics.php to:

    <?php
    
    /**
     * Pagination for pages of topics (when viewing a forum)
     *
     * @package bbPress
     * @subpackage Theme
     */
    
    // Exit if accessed directly
    defined( 'ABSPATH' ) || exit;
    
    do_action( 'bbp_template_before_pagination_loop' );
    
    // Use bbPress setting for topics per page
    $posts_per_page = bbp_get_topics_per_page();  // Dynamically get the value from bbPress settings
    
    // Get the current page
    $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
    
    // Set up the custom query
    $args = array(
        'post_type'      => bbp_get_topic_post_type(),
        'posts_per_page' => $posts_per_page,
        'paged'          => $paged,
        'meta_query'     => array(
            array(
                'key'   => '_bbp_forum_id',
                'value' => bbp_get_forum_id(),
            ),
        ),
    );
    
    // Run the custom query
    $forum_query = new WP_Query($args);
    
    if ($forum_query->have_posts()) :
    ?>
        <div class="bbp-pagination">
            <div class="bbp-pagination-count">
                <?php
                // Display the range of topics being viewed
                $start = ($paged - 1) * $posts_per_page + 1;
                $end = min($paged * $posts_per_page, $forum_query->found_posts);
                echo sprintf(__('Viewing %1$s to %2$s (of %3$s topics)'), $start, $end, $forum_query->found_posts);
                ?>
            </div>
            <div class="bbp-pagination-links">
                <?php
                // Generate the pagination links
                echo paginate_links(array(
                    'total'   => $forum_query->max_num_pages,
                    'current' => $paged,
                    'format'  => '?paged=%#%',
                    'add_args' => false,
                    'prev_text' => __('« Prev'),
                    'next_text' => __('Next »'),
                ));
                ?>
            </div>
        </div>
    <?php
    else :
        echo '<p>No topics found.</p>';
    endif;
    
    // Reset post data
    wp_reset_postdata();
    
    do_action('bbp_template_after_pagination_loop');
    ?>
    

    Replace the code inside pagination-replies.php to:

    <?php
    
    /**
     * Pagination for pages of replies (when viewing a topic)
     *
     * @package bbPress
     * @subpackage Theme
     */
    
    // Exit if accessed directly
    defined( 'ABSPATH' ) || exit;
    
    do_action( 'bbp_template_before_pagination_loop' );
    
    // Use bbPress setting for replies per page
    $posts_per_page = bbp_get_replies_per_page();  // Dynamically get the value from bbPress settings
    
    // Get the current page
    $paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
    
    // Set up the custom query
    $args = array(
        'post_type'      => bbp_get_reply_post_type(),
        'posts_per_page' => $posts_per_page,
        'paged'          => $paged,
        'meta_query'     => array(
            array(
                'key'   => '_bbp_topic_id',
                'value' => bbp_get_topic_id(),
            ),
        ),
    );
    
    // Run the custom query
    $replies_query = new WP_Query($args);
    
    if ($replies_query->have_posts()) :
    ?>
        <div class="bbp-pagination">
            <div class="bbp-pagination-count">
                <?php
                // Display the range of replies being viewed
                $start = ($paged - 1) * $posts_per_page + 1;
                $end = min($paged * $posts_per_page, $replies_query->found_posts);
                echo sprintf(__('Viewing %1$s to %2$s (of %3$s replies)'), $start, $end, $replies_query->found_posts);
                ?>
            </div>
            <div class="bbp-pagination-links">
                <?php
                // Generate the pagination links
                echo paginate_links(array(
                    'total'   => $replies_query->max_num_pages,
                    'current' => $paged,
                    'format'  => '?paged=%#%',
                    'add_args' => false,
                    'prev_text' => __('« Prev'),
                    'next_text' => __('Next »'),
                ));
                ?>
            </div>
        </div>
    <?php
    else :
        echo '<p>No replies found.</p>';
    endif;
    
    // Reset post data
    wp_reset_postdata();
    
    do_action('bbp_template_after_pagination_loop');
    ?>
    

    smelendez
    Participant

    @smelendez

    Hello, George.

    First of all, thanks for sharing that code modifications, it seems to fix the pagination for forums set up inside BuddyPress groups without any problem.

    While following your instructions, I have a problem with the pagination between replies and I would like to ask you. For testing purposes, I have set a maximum of 2 replies per page for each topic. When I create a first reply, it is displayed without problem as topic content, but when I create a second reply, it is not displayed and a new page is not created for pagination. However, when I create a third reply, a new page is created showing the second reply and the third reply.

    I think the problem could be with the initial content that is indicated when creating a topic. As you know, when you create a new topic you are asked for a title for that topic as well as some content as an introduction. When you enter the topic, this ‘introduction’ is displayed in the replies section but is not counted as a reply. So having set a maximum of 2 replies per page for each topic for testing, the first page shows the ‘introduction’ and replay 1, but when creating replay 2, as the same page is showing the ‘introduction’, this new reply is not shown and a second page is not created either as it detects only 1 replay on the first page.

    How could this be solved? On the other hand, the pagination between topics works very well.

    Thank you very much in advance, best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar