WP_List_Table::set_pagination_args() WordPress Method

The WP_List_Table::set_pagination_args() method is used to set the pagination arguments for a list table. The method takes an array of arguments as its only parameter. The array keys are used to set the various pagination arguments.

WP_List_Table::set_pagination_args( array|string $args ) #

An internal method that sets all the necessary pagination arguments


Parameters

$args

(array|string)(Required)Array or string of arguments with information about the pagination.


Top ↑

More Information

This method should be called internally (usually from prepare_items()) to set basic pagination arguments. Available arguments include:

  • total_items – the total number of items to be displayed. Usually as simple as count($data)
  • per_page – the number of items to show per page
  • total_pages – the total number of pages. Can be left blank or calculated manually, like so: ceil($total_items/$per_page)

Top ↑

Source

File: wp-admin/includes/class-wp-list-table.php

	protected function set_pagination_args( $args ) {
		$args = wp_parse_args(
			$args,
			array(
				'total_items' => 0,
				'total_pages' => 0,
				'per_page'    => 0,
			)
		);

		if ( ! $args['total_pages'] && $args['per_page'] > 0 ) {
			$args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
		}

		// Redirect if page number is invalid and headers are not already sent.
		if ( ! headers_sent() && ! wp_doing_ajax() && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
			wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
			exit;
		}

		$this->_pagination_args = $args;
	}


Top ↑

Changelog

Changelog
VersionDescription
3.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.