diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index c4db4871df644..1cf06d45b2819 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -1181,17 +1181,19 @@ public function delete_item( $request ) { protected function prepare_items_query( $prepared_args = array(), $request = null ) { $query_args = array(); - foreach ( $prepared_args as $key => $value ) { - /** - * Filters the query_vars used in get_items() for the constructed query. - * - * The dynamic portion of the hook name, `$key`, refers to the query_var key. - * - * @since 4.7.0 - * - * @param string $value The query_var value. - */ - $query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + if ( is_array( $prepared_args ) ) { + foreach ( $prepared_args as $key => $value ) { + /** + * Filters the query_vars used in get_items() for the constructed query. + * + * The dynamic portion of the hook name, `$key`, refers to the query_var key. + * + * @since 4.7.0 + * + * @param string $value The query_var value. + */ + $query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + } } if ( 'post' !== $this->post_type || ! isset( $query_args['ignore_sticky_posts'] ) ) { diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php index fb5fa29231a4f..a25d565428f90 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php @@ -532,9 +532,11 @@ public function delete_item( $request ) { protected function prepare_items_query( $prepared_args = array(), $request = null ) { $query_args = array(); - foreach ( $prepared_args as $key => $value ) { - /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */ - $query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + if ( is_array( $prepared_args ) ) { + foreach ( $prepared_args as $key => $value ) { + /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */ + $query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores + } } // Map to proper WP_Query orderby param.