BP_Blogs_Template::__construct( string $type, string $page, string $per_page, string $max, string $user_id, string $search_terms, string $page_arg = 'bpage', bool $update_meta_cache = true, array|bool $include_blog_ids = false )

Constructor method.

Description

See also

Parameters

$type

(Required) See BP_Blogs_Blog::get().

$page

(Required) See BP_Blogs_Blog::get().

$per_page

(Required) See BP_Blogs_Blog::get().

$max

(Required) See BP_Blogs_Blog::get().

$user_id

(Required) See BP_Blogs_Blog::get().

$search_terms

(Required) See BP_Blogs_Blog::get().

$page_arg

(Optional) The string used as a query parameter in pagination links. Default: 'bpage'.

Default value: 'bpage'

$update_meta_cache

(Optional) Whether to pre-fetch metadata for queried blogs.

Default value: true

$include_blog_ids

(Optional) Array of blog IDs to include.

Default value: false

Source

File: bp-blogs/classes/class-bp-blogs-template.php

	public function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage', $update_meta_cache = true, $include_blog_ids = false ) {

		$this->pag_arg  = sanitize_key( $page_arg );
		$this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $page     );
		$this->pag_num  = bp_sanitize_pagination_arg( 'num',          $per_page );

		// Backwards compatibility support for blogs by first letter.
		if ( ! empty( $_REQUEST['letter'] ) ) {
			$this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );

		// Typical blogs query.
		} else {
			$this->blogs = bp_blogs_get_blogs( array(
				'type'              => $type,
				'per_page'          => $this->pag_num,
				'page'              => $this->pag_page,
				'user_id'           => $user_id,
				'search_terms'      => $search_terms,
				'update_meta_cache' => $update_meta_cache,
				'include_blog_ids'  => $include_blog_ids,
			) );
		}

		// Set the total blog count.
		if ( empty( $max ) || ( $max >= (int) $this->blogs['total'] ) ) {
			$this->total_blog_count = (int) $this->blogs['total'];
		} else {
			$this->total_blog_count = (int) $max;
		}

		// Set the blogs array (to loop through later.
		$this->blogs = $this->blogs['blogs'];

		// Get the current blog count to compare maximum against.
		$blog_count = count( $this->blogs );

		// Set the current blog count.
		if ( empty( $max ) || ( $max >= (int) $blog_count ) ) {
			$this->blog_count = (int) $blog_count;
		} else {
			$this->blog_count = (int) $max;
		}

		// Build pagination links based on total blogs and current page number.
		if ( ! empty( $this->total_blog_count ) && ! empty( $this->pag_num ) ) {
			$this->pag_links = paginate_links( array(
				'base'      => add_query_arg( $this->pag_arg, '%#%' ),
				'format'    => '',
				'total'     => ceil( (int) $this->total_blog_count / (int) $this->pag_num ),
				'current'   => (int) $this->pag_page,
				'prev_text' => __( '←', 'buddyboss' ),
				'next_text' => __( '→', 'buddyboss' ),
				'mid_size'  => 1,
				'add_args'  => array(),
			) );
		}
	}

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.