WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#37904 closed defect (bug) (fixed)

PHP warning when `include` is passed for `orderby` in get_terms()

Reported by: rabmalin Owned by: boonebgorges
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.1
Component: Query Keywords: has-patch
Focuses: Cc:
PR Number:

Description

Steps to reproduce:

<?php
$args = array(
    'include' => '2,4,3',
    'orderby' => 'include',
    );
$terms = get_terms( $args );

Output:

Warning: array_map(): Argument #2 should be an array in /var/www/trunk.dev/public_html/wp-includes/class-wp-term-query.php on line 776

Warning: implode(): Invalid arguments passed in /var/www/trunk.dev/public_html/wp-includes/class-wp-term-query.php on line 776

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ASC' at line 1]
SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id IN ( 2,4,3 ) AND tt.count > 0 ORDER BY FIELD( t.term_id, ) ASC

Environment:

  • WP version: 4.7-alpha-38492

Attachments (2)

37904.diff (689 bytes) - added by TimothyBlynJacobs 3 years ago.
37904.tests.diff (840 bytes) - added by TimothyBlynJacobs 3 years ago.

Download all attachments as: .zip

Change History (9)

#1 @TimothyBlynJacobs
3 years ago

  • Keywords has-patch added

#2 @boonebgorges
3 years ago

  • Owner set to boonebgorges
  • Status changed from new to reviewing

#3 @boonebgorges
3 years ago

  • Milestone changed from Awaiting Review to 4.7
  • Version changed from trunk to 4.1

Thanks for the ticket and for the patches! Introduced in [30052]; it was assumed there that 'include' would always be an array, not a comma-separated list.

#4 @boonebgorges
3 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 38500:

Query: 'orderby=include' should support comma-separated lists.

[30052] assumed that 'include' would be an array.

Props TimothyBlynJacobs.
Fixes #37904.

#5 @dd32
3 years ago

@boonebgorges Do you want to target this for a potential 4.6.x?

#6 follow-up: @boonebgorges
3 years ago

@dd32 It's not a 4.6 regression, and not even a 4.1 regression, strictly - it was an oversight when the feature was first introduced. That said, it's minor and perfectly safe for 4.6.x inclusion, if you think it's warranted.

#7 in reply to: ↑ 6 @dd32
3 years ago

Replying to boonebgorges:

@dd32 It's not a 4.6 regression, and not even a 4.1 regression, strictly - it was an oversight when the feature was first introduced. That said, it's minor and perfectly safe for 4.6.x inclusion, if you think it's warranted.

I misread it and thought that orderby=include was a 4.6 thing, never mind, this doesn't need to be in a 4.6.x

Note: See TracTickets for help on using tickets.