WP_REST_Menu_Items_Controller::get_collection_params() WordPress Method

The WP_REST_Menu_Items_Controller::get_collection_params() method allows you to specify the parameters that will be used to retrieve a collection of menu items. This is useful if you want to limit the number of items that are returned, or if you want to order the items by a specific field.

WP_REST_Menu_Items_Controller::get_collection_params() #

Retrieves the query params for the posts collection.


Return

(array) Collection parameters.


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php

	public function get_collection_params() {
		$query_params = parent::get_collection_params();

		$query_params['menu_order'] = array(
			'description' => __( 'Limit result set to posts with a specific menu_order value.' ),
			'type'        => 'integer',
		);

		$query_params['order'] = array(
			'description' => __( 'Order sort attribute ascending or descending.' ),
			'type'        => 'string',
			'default'     => 'asc',
			'enum'        => array( 'asc', 'desc' ),
		);

		$query_params['orderby'] = array(
			'description' => __( 'Sort collection by object attribute.' ),
			'type'        => 'string',
			'default'     => 'menu_order',
			'enum'        => array(
				'author',
				'date',
				'id',
				'include',
				'modified',
				'parent',
				'relevance',
				'slug',
				'include_slugs',
				'title',
				'menu_order',
			),
		);
		// Change default to 100 items.
		$query_params['per_page']['default'] = 100;

		return $query_params;
	}


Top ↑

Changelog

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