From d4822bd3c57bb33c4a2d5da62db8be1709c9e0b8 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Mon, 10 Feb 2025 22:23:23 +0000 Subject: [PATCH] REST API: Add support for the `ignore_sticky_posts` argument. Introduce `ignore_sticky` as a boolean argument for the posts endpoint for requests without the sticky posts being stuck. The new argument defaults to `false` with the value of the argument passed to `WP_Query`'s `ignore_sticky_posts` parameter. Props audrasjb, danielbachhuber, joemcgill, johnbillion, jorbin, mamaduka, rmccue. Fixes #35907. Built from https://develop.svn.wordpress.org/trunk@59801 git-svn-id: http://core.svn.wordpress.org/trunk@59143 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../endpoints/class-wp-rest-posts-controller.php | 15 +++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 6f872be3df..cb25207fc5 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -247,6 +247,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'author_exclude' => 'author__not_in', 'exclude' => 'post__not_in', 'include' => 'post__in', + 'ignore_sticky' => 'ignore_sticky_posts', 'menu_order' => 'menu_order', 'offset' => 'offset', 'order' => 'order', @@ -337,6 +338,14 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { } } + /* + * Honor the original REST API `post__in` behavior. Don't prepend sticky posts + * when `post__in` has been specified. + */ + if ( ! empty( $args['post__in'] ) ) { + unset( $args['ignore_sticky_posts'] ); + } + if ( isset( $registered['search_semantics'], $request['search_semantics'] ) && 'exact' === $request['search_semantics'] @@ -3045,6 +3054,12 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'description' => __( 'Limit result set to items that are sticky.' ), 'type' => 'boolean', ); + + $query_params['ignore_sticky'] = array( + 'description' => __( 'Whether to ignore sticky posts or not.' ), + 'type' => 'boolean', + 'default' => false, + ); } if ( post_type_supports( $this->post_type, 'post-formats' ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index d12079c23e..0310006bc9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8-alpha-59800'; +$wp_version = '6.8-alpha-59801'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.