WP_Sitemaps_Posts::get_posts_query_args() WordPress Method

The WP_Sitemaps_Posts::get_posts_query_args() method allows you to modify the query arguments used when retrieving posts for the sitemap. This can be useful if you want to exclude certain posts or post types from the sitemap.

WP_Sitemaps_Posts::get_posts_query_args( string $post_type ) #

Returns the query args for retrieving posts to list in the sitemap.


Parameters

$post_type

(string)(Required)Post type name.


Top ↑

Return

(array) Array of WP_Query arguments.


Top ↑

Source

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

	protected function get_posts_query_args( $post_type ) {
		/**
		 * Filters the query arguments for post type sitemap queries.
		 *
		 * @see WP_Query for a full list of arguments.
		 *
		 * @since 5.5.0
		 *
		 * @param array  $args      Array of WP_Query arguments.
		 * @param string $post_type Post type name.
		 */
		$args = apply_filters(
			'wp_sitemaps_posts_query_args',
			array(
				'orderby'                => 'ID',
				'order'                  => 'ASC',
				'post_type'              => $post_type,
				'posts_per_page'         => wp_sitemaps_get_max_urls( $this->object_type ),
				'post_status'            => array( 'publish' ),
				'no_found_rows'          => true,
				'update_post_term_cache' => false,
				'update_post_meta_cache' => false,
			),
			$post_type
		);

		return $args;
	}


Top ↑

Changelog

Changelog
VersionDescription
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.