Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/18/2022 11:06:15 PM (3 years ago)
Author:
r-a-y
Message:

Blogs: Fix pagination in BP_Blogs_Blog::get().

As part of #8488, we refactored BP_Blogs_Blog::get() to use an array
as the main function argument instead of passing multiple function
arguments.

In BP_Blogs_Blog::get(), the "per page" argument was previously
$limit, while in bp_blogs_get_blogs(), the "per page" argument
passed to BP_Blogs_Blog::get() is $r['per_page']. When swapping
over to the array function argument, $r['limit'] does not exist,
which broke pagination and would return all blogs instead.

This commit fixes the pagination problem by renaming the array key
from $r['limit'] to $r['per_page'].

Props imath.

Fixes #8633 (trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/classes/class-bp-blogs-blog.php

    r13184 r13236  
    171171     *     @type string      $type              The order in which results should be returned.
    172172     *                                          'active', 'alphabetical', 'newest', or 'random'.
    173      *     @type int|bool    $limit             Optional. The maximum records to return.
     173     *     @type int|bool    $per_page          Optional. The number of records to return per page.
    174174     *                                          Default: false.
    175175     *     @type int|bool    $page              Optional. The page of records to return.
     
    201201            $old_args_keys = [
    202202                0  => 'type',
    203                 1  => 'limit',
     203                1  => 'per_page',
    204204                2  => 'page',
    205205                3  => 'user_id',
     
    218218            array(
    219219                'type'              => 'active',
    220                 'limit'             => false,
     220                'per_page'          => false,
    221221                'page'              => false,
    222222                'user_id'           => 0,
     
    234234        }
    235235
    236         $pag_sql = ( $r['limit'] && $r['page'] ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $r['page'] - 1 ) * $r['limit']), intval( $r['limit'] ) ) : '';
     236        $pag_sql = ( $r['per_page'] && $r['page'] ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $r['page'] - 1 ) * $r['per_page']), intval( $r['per_page'] ) ) : '';
    237237
    238238        $user_sql = ! empty( $r['user_id'] ) ? $wpdb->prepare( " AND b.user_id = %d", $r['user_id'] ) : '';
Note: See TracChangeset for help on using the changeset viewer.