WP_REST_Menu_Items_Controller::prepare_items_query() WordPress Method

The WP_REST_Menu_Items_Controller::prepare_items_query() method is used to prepare the menu items query for a REST request. This method sets the necessary query parameters for menu items and ensures that only the allowed menu items are returned.

WP_REST_Menu_Items_Controller::prepare_items_query( array $prepared_args = array(), WP_REST_Request $request = null ) #

Determines the allowed query_vars for a get_items() response and prepares them for WP_Query.


Parameters

$prepared_args

(array)(Optional) Prepared WP_Query arguments.

Default value: array()

$request

(WP_REST_Request)(Optional) Full details about the request.

Default value: null


Top ↑

Return

(array) Items query arguments.


Top ↑

Source

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

	protected function prepare_items_query( $prepared_args = array(), $request = null ) {
		$query_args = parent::prepare_items_query( $prepared_args, $request );

		// Map to proper WP_Query orderby param.
		if ( isset( $query_args['orderby'], $request['orderby'] ) ) {
			$orderby_mappings = array(
				'id'            => 'ID',
				'include'       => 'post__in',
				'slug'          => 'post_name',
				'include_slugs' => 'post_name__in',
				'menu_order'    => 'menu_order',
			);

			if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) {
				$query_args['orderby'] = $orderby_mappings[ $request['orderby'] ];
			}
		}

		return $query_args;
	}


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.