WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/26/2021 06:26:13 PM (4 months ago)
Author:
johnbillion
Message:

REST API: Introduce modified_before and modified_after query parameters for the posts endpoints.

These parameters work just the same as before and after except they operate on the post modified date instead of the post published date.

Props claytoncollie, TimothyBlynJacobs, hellofromTonya

Fixes #50617

File:
1 edited

Legend:

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

    r49942 r50024  
    217217        $args['date_query'] = array();
    218218
    219         // Set before into date query. Date query must be specified as an array of an array.
    220219        if ( isset( $registered['before'], $request['before'] ) ) {
    221             $args['date_query'][0]['before'] = $request['before'];
    222         }
    223 
    224         // Set after into date query. Date query must be specified as an array of an array.
     220            $args['date_query'][] = array(
     221                'before' => $request['before'],
     222                'column' => 'post_date',
     223            );
     224        }
     225
     226        if ( isset( $registered['modified_before'], $request['modified_before'] ) ) {
     227            $args['date_query'][] = array(
     228                'before' => $request['modified_before'],
     229                'column' => 'post_modified',
     230            );
     231        }
     232
    225233        if ( isset( $registered['after'], $request['after'] ) ) {
    226             $args['date_query'][0]['after'] = $request['after'];
     234            $args['date_query'][] = array(
     235                'after'  => $request['after'],
     236                'column' => 'post_date',
     237            );
     238        }
     239
     240        if ( isset( $registered['modified_after'], $request['modified_after'] ) ) {
     241            $args['date_query'][] = array(
     242                'after'  => $request['modified_after'],
     243                'column' => 'post_modified',
     244            );
    227245        }
    228246
     
    26292647     *
    26302648     * @since 4.7.0
     2649     * @since 5.4.0 The `tax_relation` query parameter was added.
     2650     * @since 5.7.0 The `modified_after` and `modified_before` query parameters were added.
    26312651     *
    26322652     * @return array Collection parameters.
     
    26392659        $query_params['after'] = array(
    26402660            'description' => __( 'Limit response to posts published after a given ISO8601 compliant date.' ),
     2661            'type'        => 'string',
     2662            'format'      => 'date-time',
     2663        );
     2664
     2665        $query_params['modified_after'] = array(
     2666            'description' => __( 'Limit response to posts modified after a given ISO8601 compliant date.' ),
    26412667            'type'        => 'string',
    26422668            'format'      => 'date-time',
     
    26642690        $query_params['before'] = array(
    26652691            'description' => __( 'Limit response to posts published before a given ISO8601 compliant date.' ),
     2692            'type'        => 'string',
     2693            'format'      => 'date-time',
     2694        );
     2695
     2696        $query_params['modified_before'] = array(
     2697            'description' => __( 'Limit response to posts modified before a given ISO8601 compliant date.' ),
    26662698            'type'        => 'string',
    26672699            'format'      => 'date-time',
Note: See TracChangeset for help on using the changeset viewer.