WP_Screen::render_per_page_options()

In this article

Renders the items per page option.

Source

public function render_per_page_options() {
	if ( null === $this->get_option( 'per_page' ) ) {
		return;
	}

	$per_page_label = $this->get_option( 'per_page', 'label' );
	if ( null === $per_page_label ) {
		$per_page_label = __( 'Number of items per page:' );
	}

	$option = $this->get_option( 'per_page', 'option' );
	if ( ! $option ) {
		$option = str_replace( '-', '_', "{$this->id}_per_page" );
	}

	$per_page = (int) get_user_option( $option );
	if ( empty( $per_page ) || $per_page < 1 ) {
		$per_page = $this->get_option( 'per_page', 'default' );
		if ( ! $per_page ) {
			$per_page = 20;
		}
	}

	if ( 'edit_comments_per_page' === $option ) {
		$comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';

		/** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
		$per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
	} elseif ( 'categories_per_page' === $option ) {
		/** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */
		$per_page = apply_filters( 'edit_categories_per_page', $per_page );
	} else {
		/** This filter is documented in wp-admin/includes/class-wp-list-table.php */
		$per_page = apply_filters( "{$option}", $per_page );
	}

	// Back compat.
	if ( isset( $this->post_type ) ) {
		/** This filter is documented in wp-admin/includes/post.php */
		$per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
	}

	// This needs a submit button.
	add_filter( 'screen_options_show_submit', '__return_true' );

	?>
	<fieldset class="screen-options">
	<legend><?php _e( 'Pagination' ); ?></legend>
		<?php if ( $per_page_label ) : ?>
			<label for="<?php echo esc_attr( $option ); ?>"><?php echo $per_page_label; ?></label>
			<input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]"
				id="<?php echo esc_attr( $option ); ?>"
				value="<?php echo esc_attr( $per_page ); ?>" />
		<?php endif; ?>
			<input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" />
	</fieldset>
	<?php
}

Hooks

apply_filters( ‘comments_per_page’, int $comments_per_page, string $comment_status )

Filters the number of comments listed per page in the comments list table.

apply_filters( ‘edit_categories_per_page’, int $tags_per_page )

Filters the number of terms displayed per page for the Categories list table.

apply_filters( ‘edit_posts_per_page’, int $posts_per_page, string $post_type )

Filters the number of posts displayed per page when specifically listing “posts”.

apply_filters( “{$option}”, int $per_page )

Filters the number of items to be displayed on each page of the list table.

Changelog

VersionDescription
3.3.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.