WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 3 weeks ago

#25835 new defect (bug)

WP_Date_Query duplicated Parameters

Reported by: ChriCo Owned by:
Milestone: Future Release Priority: low
Severity: normal Version: 3.7
Component: Query Keywords: has-patch dev-feedback
Focuses: Cc:

Description

In WP_Date_Query-Class there a 2 duplicated Parameters:

  • month <-> monthnum
  • week <-> w

When creating an Query, we can set both of them:

$date_query = new WP_Date_Query( array(
  'w' => 12,
  'week' => 11
));
echo $date_query->get_sql();
/*
AND ( 
  ( WEEK( post_date, 1 ) = 11 
  AND WEEK( post_date, 1 ) = 12 ) 
)
*/

and:

$date_query = new WP_Date_Query( array(
'month' => 12,
'monthnum' => 11
));
echo $date_query->get_sql();
/*
AND ( 
  ( MONTH( post_date ) = 12 
  AND MONTH( post_date ) = 11 ) 
)
*/

In date.php should be an else if to avoid the duplicated AND-Search with no result at all:

if ( isset( $query['week'] ) && false !== ( $value = $this->build_value( $compare, $query['week'] ) ) )
	$where_parts[] = _wp_mysql_week( $column ) . " $compare $value";
else if ( isset( $query['w'] ) && false !== ( $value = $this->build_value( $compare, $query['w'] ) ) )
	$where_parts[] = _wp_mysql_week( $column ) . " $compare $value";

and..

if ( isset( $query['month'] ) && $value = $this->build_value( $compare, $query['month'] ) )
	$where_parts[] = "MONTH( $column ) $compare $value";
else if ( isset( $query['monthnum'] ) && $value = $this->build_value( $compare, $query['monthnum'] ) )
	$where_parts[] = "MONTH( $column ) $compare $value";

Attachments (4)

date.php.rej (1.6 KB) - added by ChriCo 5 months ago.
git diff
25835.diff (1.2 KB) - added by ChriCo 5 months ago.
Diff
unit-test.25835.diff (2.3 KB) - added by oso96_2000 3 months ago.
Unit test and fixed diff route
unit-test.25835.2.diff (2.8 KB) - added by oso96_2000 2 months ago.
More tests

Download all attachments as: .zip

Change History (14)

comment:1 toscho5 months ago

  • Cc info@… added

comment:2 SergeyBiryukov5 months ago

  • Component changed from Date/Time to Query
  • Version changed from 3.7.1 to 3.7

Related: #25834

ChriCo5 months ago

git diff

comment:3 ChriCo5 months ago

I've added a .diff-File ( pls ignore the file-extension ) to fix this problem.

comment:5 emzo5 months ago

  • Cc wordpress@… added

ChriCo5 months ago

Diff

comment:6 wonderboymusic3 months ago

  • Keywords has-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to 3.9

oso96_20003 months ago

Unit test and fixed diff route

comment:7 oso96_20003 months ago

Hope the unit test works. Also uploaded the diff with the whole change since the path to the file has changed.

oso96_20002 months ago

More tests

comment:8 oso96_20002 months ago

  • Keywords needs-unit-tests removed

Wasn't happy with the tests uploaded before so I added one more assert to each test to check for returned posts.

comment:9 oso96_20002 months ago

  • Keywords dev-feedback added

comment:10 nacin3 weeks ago

  • Milestone changed from 3.9 to Future Release
  • Priority changed from normal to low

This isn't a huge deal, moving to Future, we can pick it up in 4.0.

Note: See TracTickets for help on using tickets.