Make WordPress Core


Ignore:
Timestamp:
02/10/2025 10:21:51 PM (3 months ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r59630 r59801  
    248248            'exclude'        => 'post__not_in',
    249249            'include'        => 'post__in',
     250            'ignore_sticky'  => 'ignore_sticky_posts',
    250251            'menu_order'     => 'menu_order',
    251252            'offset'         => 'offset',
     
    336337                $args['post__not_in'] = array_merge( $args['post__not_in'], $sticky_posts );
    337338            }
     339        }
     340
     341        /*
     342         * Honor the original REST API `post__in` behavior. Don't prepend sticky posts
     343         * when `post__in` has been specified.
     344         */
     345        if ( ! empty( $args['post__in'] ) ) {
     346            unset( $args['ignore_sticky_posts'] );
    338347        }
    339348
     
    30463055                'type'        => 'boolean',
    30473056            );
     3057
     3058            $query_params['ignore_sticky'] = array(
     3059                'description' => __( 'Whether to ignore sticky posts or not.' ),
     3060                'type'        => 'boolean',
     3061                'default'     => false,
     3062            );
    30483063        }
    30493064
Note: See TracChangeset for help on using the changeset viewer.