@@ -137,6 +137,19 @@ class Date extends Base {
137
137
'AND '
138
138
);
139
139
140
+
141
+ /**
142
+ * @since 3.2.6
143
+ * @var string|null Table name
144
+ */
145
+ public $ table_name = null ;
146
+
147
+ /**
148
+ * @since 3.2.6
149
+ * @var string|null Table alias
150
+ */
151
+ public $ table_alias = null ;
152
+
140
153
/**
141
154
* Constructor.
142
155
*
@@ -145,79 +158,79 @@ class Date extends Base {
145
158
* 'compare'. When 'compare' is 'IN' or 'NOT IN', arrays are accepted; when 'compare' is 'BETWEEN' or 'NOT
146
159
* BETWEEN', arrays of two valid values are required. See individual argument descriptions for accepted values.
147
160
*
148
- * @since 1.0.0
149
- *
150
161
* @param array $date_query {
151
162
* Array of date query clauses.
152
163
*
153
- * @type array {
154
- * @type string $column Optional. The column to query against. If undefined, inherits the value of
164
+ * @type array {
165
+ * @type string $column Optional. The column to query against. If undefined, inherits the value of
155
166
* 'date_created'. Accepts 'date_created', 'date_created_gmt',
156
167
* 'post_modified','post_modified_gmt', 'comment_date', 'comment_date_gmt'.
157
168
* Default 'date_created'.
158
- * @type string $compare Optional. The comparison operator. Accepts '=', '!=', '>', '>=', '<', '<=',
169
+ * @type string $compare Optional. The comparison operator. Accepts '=', '!=', '>', '>=', '<', '<=',
159
170
* 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. Default '='.
160
- * @type string $relation Optional. The boolean relationship between the date queries. Accepts 'OR' or 'AND'.
171
+ * @type string $relation Optional. The boolean relationship between the date queries. Accepts 'OR' or 'AND'.
161
172
* Default 'OR'.
162
- * @type array {
173
+ * @type array {
163
174
* Optional. An array of first-order clause parameters, or another fully-formed date query.
164
175
*
165
- * @type string|array $before {
176
+ * @type string|array $before {
166
177
* Optional. Date to retrieve posts before. Accepts `strtotime()`-compatible string,
167
178
* or array of 'year', 'month', 'day' values.
168
179
*
169
- * @type string $year The four-digit year. Default empty. Accepts any four-digit year.
170
- * @type string $month Optional when passing array.The month of the year.
180
+ * @type string $year The four-digit year. Default empty. Accepts any four-digit year.
181
+ * @type string $month Optional when passing array.The month of the year.
171
182
* Default (string:empty)|(array:1). Accepts numbers 1-12.
172
- * @type string $day Optional when passing array.The day of the month.
183
+ * @type string $day Optional when passing array.The day of the month.
173
184
* Default (string:empty)|(array:1). Accepts numbers 1-31.
174
185
* }
175
- * @type string|array $after {
186
+ * @type string|array $after {
176
187
* Optional. Date to retrieve posts after. Accepts `strtotime()`-compatible string,
177
188
* or array of 'year', 'month', 'day' values.
178
189
*
179
- * @type string $year The four-digit year. Accepts any four-digit year. Default empty.
180
- * @type string $month Optional when passing array. The month of the year. Accepts numbers 1-12.
190
+ * @type string $year The four-digit year. Accepts any four-digit year. Default empty.
191
+ * @type string $month Optional when passing array. The month of the year. Accepts numbers 1-12.
181
192
* Default (string:empty)|(array:12).
182
- * @type string $day Optional when passing array.The day of the month. Accepts numbers 1-31.
193
+ * @type string $day Optional when passing array.The day of the month. Accepts numbers 1-31.
183
194
* Default (string:empty)|(array:last day of month).
184
195
* }
185
- * @type string $column Optional. Used to add a clause comparing a column other than the
196
+ * @type string $column Optional. Used to add a clause comparing a column other than the
186
197
* column specified in the top-level `$column` parameter. Accepts
187
198
* 'date_created', 'date_created_gmt', 'post_modified', 'post_modified_gmt',
188
199
* 'comment_date', 'comment_date_gmt'. Default is the value of
189
200
* top-level `$column`.
190
- * @type string $compare Optional. The comparison operator. Accepts '=', '!=', '>', '>=',
201
+ * @type string $compare Optional. The comparison operator. Accepts '=', '!=', '>', '>=',
191
202
* '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. 'IN',
192
203
* 'NOT IN', 'BETWEEN', and 'NOT BETWEEN'. Comparisons support
193
204
* arrays in some time-related parameters. Default '='.
194
- * @type bool $inclusive Optional. Include results from dates specified in 'before' or
205
+ * @type bool $inclusive Optional. Include results from dates specified in 'before' or
195
206
* 'after'. Default false.
196
- * @type int|array $year Optional. The four-digit year number. Accepts any four-digit year
207
+ * @type int|array $year Optional. The four-digit year number. Accepts any four-digit year
197
208
* or an array of years if `$compare` supports it. Default empty.
198
- * @type int|array $month Optional. The two-digit month number. Accepts numbers 1-12 or an
209
+ * @type int|array $month Optional. The two-digit month number. Accepts numbers 1-12 or an
199
210
* array of valid numbers if `$compare` supports it. Default empty.
200
- * @type int|array $week Optional. The week number of the year. Accepts numbers 0-53 or an
211
+ * @type int|array $week Optional. The week number of the year. Accepts numbers 0-53 or an
201
212
* array of valid numbers if `$compare` supports it. Default empty.
202
- * @type int|array $dayofyear Optional. The day number of the year. Accepts numbers 1-366 or an
213
+ * @type int|array $dayofyear Optional. The day number of the year. Accepts numbers 1-366 or an
203
214
* array of valid numbers if `$compare` supports it.
204
- * @type int|array $day Optional. The day of the month. Accepts numbers 1-31 or an array
215
+ * @type int|array $day Optional. The day of the month. Accepts numbers 1-31 or an array
205
216
* of valid numbers if `$compare` supports it. Default empty.
206
- * @type int|array $dayofweek Optional. The day number of the week. Accepts numbers 1-7 (1 is
217
+ * @type int|array $dayofweek Optional. The day number of the week. Accepts numbers 1-7 (1 is
207
218
* Sunday) or an array of valid numbers if `$compare` supports it.
208
219
* Default empty.
209
- * @type int|array $dayofweek_iso Optional. The day number of the week (ISO). Accepts numbers 1-7
220
+ * @type int|array $dayofweek_iso Optional. The day number of the week (ISO). Accepts numbers 1-7
210
221
* (1 is Monday) or an array of valid numbers if `$compare` supports it.
211
222
* Default empty.
212
- * @type int|array $hour Optional. The hour of the day. Accepts numbers 0-23 or an array
223
+ * @type int|array $hour Optional. The hour of the day. Accepts numbers 0-23 or an array
213
224
* of valid numbers if `$compare` supports it. Default empty.
214
- * @type int|array $minute Optional. The minute of the hour. Accepts numbers 0-60 or an array
225
+ * @type int|array $minute Optional. The minute of the hour. Accepts numbers 0-60 or an array
215
226
* of valid numbers if `$compare` supports it. Default empty.
216
- * @type int|array $second Optional. The second of the minute. Accepts numbers 0-60 or an
227
+ * @type int|array $second Optional. The second of the minute. Accepts numbers 0-60 or an
217
228
* array of valid numbers if `$compare` supports it. Default empty.
218
229
* }
219
230
* }
220
231
* }
232
+ * @since 1.0.0
233
+ *
221
234
*/
222
235
public function __construct ( $ date_query = array () ) {
223
236
@@ -362,6 +375,12 @@ public function get_column( $query = array() ) {
362
375
? esc_sql ( $ this ->validate_column ( $ query ['column ' ] ) )
363
376
: $ this ->column ;
364
377
378
+ if (!empty ($ this ->table_alias )) {
379
+ $ retval = $ this ->table_alias . '. ' . $ retval ;
380
+ } elseif (!empty ($ this ->table_name )) {
381
+ $ retval = $ this ->table_name . '. ' . $ retval ;
382
+ }
383
+
365
384
return $ retval ;
366
385
}
367
386
@@ -602,11 +621,17 @@ public function validate_column( $column = '' ) {
602
621
* Generate WHERE clause to be appended to a main query.
603
622
*
604
623
* @since 1.0.0
624
+ * @param string $table_name Optional. Table name. Default null.
625
+ * @param string $table_alias Optional. Table alias. Default null.
605
626
*
606
627
* @return string MySQL WHERE clauses.
607
628
*/
608
629
public function get_sql () {
609
630
$ sql = $ this ->get_sql_clauses ();
631
+ public function get_sql ( $ table_name = null , $ table_alias = null ) {
632
+ $ this ->table_name = $ this ->sanitize_table_name ( $ table_name );
633
+ $ this ->table_alias = $ this ->sanitize_table_name ( $ table_alias );
634
+ $ sql = $ this ->get_sql_clauses ();
610
635
611
636
/**
612
637
* Filters the date query clauses.
0 commit comments