WP_Sitemaps_Posts::get_max_num_pages() WordPress Method

The WP_Sitemaps_Posts::get_max_num_pages() function is used to return the maximum number of pages for a post type.

WP_Sitemaps_Posts::get_max_num_pages( string $object_subtype = '' ) #

Gets the max number of pages available for the object type.


Parameters

$object_subtype

(string)(Optional) Post type name.

Default value: ''


Top ↑

Return

(int) Total number of pages.


Top ↑

Source

File: wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php

	public function get_max_num_pages( $object_subtype = '' ) {
		if ( empty( $object_subtype ) ) {
			return 0;
		}

		// Restores the more descriptive, specific name for use within this method.
		$post_type = $object_subtype;

		/**
		 * Filters the max number of pages before it is generated.
		 *
		 * Passing a non-null value will short-circuit the generation,
		 * returning that value instead.
		 *
		 * @since 5.5.0
		 *
		 * @param int|null $max_num_pages The maximum number of pages. Default null.
		 * @param string   $post_type     Post type name.
		 */
		$max_num_pages = apply_filters( 'wp_sitemaps_posts_pre_max_num_pages', null, $post_type );

		if ( null !== $max_num_pages ) {
			return $max_num_pages;
		}

		$args                  = $this->get_posts_query_args( $post_type );
		$args['fields']        = 'ids';
		$args['no_found_rows'] = false;

		$query = new WP_Query( $args );

		$min_num_pages = ( 'page' === $post_type && 'posts' === get_option( 'show_on_front' ) ) ? 1 : 0;
		return isset( $query->max_num_pages ) ? max( $min_num_pages, $query->max_num_pages ) : 1;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Renamed $post_type to $object_subtype to match parent class for PHP 8 named parameter support.
5.5.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.