Make WordPress Core

Changeset 25139


Ignore:
Timestamp:
08/27/2013 04:38:32 PM (13 years ago)
Author:
nacin
Message:

WP_Date_Query.

props Viper007Bond.
see #18694.

Location:
trunk
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r25126 r25139  
    196196         */
    197197        var $meta_query = false;
     198
     199        /**
     200         * Date query container
     201         *
     202         * @since 3.7.0
     203         * @access public
     204         * @var object WP_Date_Query
     205         */
     206        var $date_query = false;
    198207
    199208        /**
    … …  
    232241                        'meta_value' => '',
    233242                        'meta_query' => '',
     243                        'date_query' => null, // See WP_Date_Query
    234244                );
    235245
    … …  
    361371                }
    362372
     373                if ( ! empty( $date_query ) && is_array( $date_query ) ) {
     374                        $date_query_object = new WP_Date_Query( $date_query, 'comment_date' );
     375                        $where .= $date_query_object->get_sql();
     376                }
     377
    363378                $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits', 'groupby' );
    364379                $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) );
  • trunk/src/wp-includes/query.php

    r25138 r25139  
    866866         */
    867867        var $meta_query = false;
     868
     869        /**
     870         * Date query container
     871         *
     872         * @since 3.7.0
     873         * @access public
     874         * @var object WP_Date_Query
     875         */
     876        var $date_query = false;
    868877
    869878        /**
    … …  
    20462055                        $where .= " AND $wpdb->posts.menu_order = " . $q['menu_order'];
    20472056
    2048                 // If a month is specified in the querystring, load that month
     2057                // The "m" parameter is meant for months but accepts datetimes of varying specificity
    20492058                if ( $q['m'] ) {
    20502059                        $where .= " AND YEAR($wpdb->posts.post_date)=" . substr($q['m'], 0, 4);
    … …  
    20612070                }
    20622071
     2072                // Handle the other individual date parameters
     2073                $date_parameters = array();
     2074
    20632075                if ( '' !== $q['hour'] )
    2064                         $where .= " AND HOUR($wpdb->posts.post_date)='" . $q['hour'] . "'";
     2076                        $date_parameters['hour'] = $q['hour'];
    20652077
    20662078                if ( '' !== $q['minute'] )
    2067                         $where .= " AND MINUTE($wpdb->posts.post_date)='" . $q['minute'] . "'";
     2079                        $date_parameters['minute'] = $q['minute'];
    20682080
    20692081                if ( '' !== $q['second'] )
    2070                         $where .= " AND SECOND($wpdb->posts.post_date)='" . $q['second'] . "'";
     2082                        $date_parameters['second'] = $q['second'];
    20712083
    20722084                if ( $q['year'] )
    2073                         $where .= " AND YEAR($wpdb->posts.post_date)='" . $q['year'] . "'";
     2085                        $date_parameters['year'] = $q['year'];
    20742086
    20752087                if ( $q['monthnum'] )
    2076                         $where .= " AND MONTH($wpdb->posts.post_date)='" . $q['monthnum'] . "'";
     2088                        $date_parameters['monthnum'] = $q['monthnum'];
     2089
     2090                if ( $q['w'] )
     2091                        $date_parameters['week'] = $q['w'];
    20772092
    20782093                if ( $q['day'] )
    2079                         $where .= " AND DAYOFMONTH($wpdb->posts.post_date)='" . $q['day'] . "'";
     2094                        $date_parameters['day'] = $q['day'];
     2095
     2096                if ( $date_parameters ) {
     2097                        $date_query = new WP_Date_Query( array( $date_parameters ) );
     2098                        $where .= $date_query->get_sql();
     2099                }
     2100                unset( $date_parameters, $date_query );
     2101
     2102                // Handle complex date queries
     2103                if ( ! empty( $q['date_query'] ) ) {
     2104                        $this->date_query = new WP_Date_Query( $q['date_query'] );
     2105                        $where .= $this->date_query->get_sql();
     2106                }
     2107
    20802108
    20812109                // If we've got a post_type AND it's not "any" post_type.
    … …  
    21472175                }
    21482176
    2149                 if ( $q['w'] )
    2150                         $where .= ' AND ' . _wp_mysql_week( "`$wpdb->posts`.`post_date`" ) . " = '" . $q['w'] . "'";
    21512177
    21522178                if ( intval($q['comments_popup']) )
  • trunk/src/wp-settings.php

    r25001 r25139  
    108108require( ABSPATH . WPINC . '/capabilities.php' );
    109109require( ABSPATH . WPINC . '/query.php' );
     110require( ABSPATH . WPINC . '/date.php' );
    110111require( ABSPATH . WPINC . '/theme.php' );
    111112require( ABSPATH . WPINC . '/class-wp-theme.php' );
Note: See TracChangeset for help on using the changeset viewer.