WordPress.org

Make WordPress Core

Ticket #28063: 28063-weekday.diff

File 28063-weekday.diff, 2.4 KB (added by mboynes, 7 years ago)

Adding an additional argument to WP_Date_Query for 'weekday', an ISO-8601-compliant way to query day of week

  • src/wp-includes/date.php

     
    9494         *             @type int          $week      Optional. The week number of the year. Default empty. Accepts numbers 0-53.
    9595         *             @type int          $dayofyear Optional. The day number of the year. Default empty. Accepts numbers 1-366.
    9696         *             @type int          $day       Optional. The day of the month. Default empty. Accepts numbers 1-31.
    97          *             @type int          $dayofweek Optional. The day number of the week. Default empty. Accepts numbers 1-7.
     97         *             @type int          $weekday   Optional. The day number of the week. Default empty. Accepts numbers 1-7, where 1=Monday and 7=Sunday.
    9898         *             @type int          $hour      Optional. The hour of the day. Default empty. Accepts numbers 0-23.
    9999         *             @type int          $minute    Optional. The minute of the hour. Default empty. Accepts numbers 0-60.
    100100         *             @type int          $second    Optional. The second of the minute. Default empty. Accepts numbers 0-60.
     
    274274                if ( isset( $query['day'] ) && $value = $this->build_value( $compare, $query['day'] ) )
    275275                        $where_parts[] = "DAYOFMONTH( $column ) $compare $value";
    276276
     277                // Legacy
    277278                if ( isset( $query['dayofweek'] ) && $value = $this->build_value( $compare, $query['dayofweek'] ) )
    278279                        $where_parts[] = "DAYOFWEEK( $column ) $compare $value";
    279280
     281                if ( isset( $query['weekday'] ) && $value = $this->build_value( $compare, $query['weekday'] ) )
     282                        $where_parts[] = "WEEKDAY( $column ) + 1 $compare $value";
     283
    280284                if ( isset( $query['hour'] ) || isset( $query['minute'] ) || isset( $query['second'] ) ) {
    281285                        // Avoid notices
    282286                        foreach ( array( 'hour', 'minute', 'second' ) as $unit ) {
  • tests/phpunit/tests/query/dateQuery.php

     
    375375                $posts = $this->_get_query_result( array(
    376376                        'date_query' => array(
    377377                                array(
    378                                         'dayofweek' => 7,
     378                                        'weekday' => 6,
    379379                                ),
    380380                        ),
    381381                ) );
     
    555555
    556556                $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    557557        }
    558 }
    559  No newline at end of file
     558}