#11076 closed enhancement (fixed)
Allow 'include' & 'exclude' args to be arrays
Reported by: | scribu | Owned by: | scribu |
---|---|---|---|
Milestone: | 3.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Most of the time, the term ids you want to include are retrieved as an array, using $wpdb.
To avoid having to join(',', $term_ids), only to have them preg_split() afterwards, I think this would be really useful.
Attachments (5)
Change History (21)
#4
@
15 years ago
Looks like we should also do this for $exclude_tree
and we should probably set the default values at the top of the function to array()
instead of ''
so we can avoid the preg_split
.
Wondering if we should refactor some of this code into a helper function as we have a lot of copy/paste going on here.
#5
@
15 years ago
get_terms.3.diff creates a helper function called _parse_get_terms_arg() and applies it to exclude, exclude_tree and include.
#6
@
15 years ago
get_terms.4.diff moves the helper function wp_parse_id_list() to wp-includes/functions.php so that it can be used in other contexts.
#8
@
15 years ago
I think it will be better to change generated SQL from:
AND (t.term_id = 1 OR t.term_id = 2 OR ...) AND (t.term_id <> 1 AND t.term_id <> 2 AND ...)
to:
AND t.term_id IN (1, 2, ...) AND t.term_id NOT IN (1, 2, ...)
#10
@
15 years ago
- Keywords needs-patch added; has-patch commit removed
- Resolution fixed deleted
- Status changed from closed to reopened
- Summary changed from In get_terms(), allow 'include' & 'exclude' args to be arrays to Allow 'include' & 'exclude' args to be arrays
Should also do this for get_pages() and get_posts()
#12
@
15 years ago
- Keywords has-patch commit added; needs-patch removed
post.php.diff:
- use wp_parse_id_list() in get_posts() and get_pages()
- replace
if ( count(...) )
withif ( !empty(...) )
#15
@
14 years ago
I'm trying to figure out if something blew up here. In version 2.9 this was working fine:
$ids = implode(',', $ids); $taxonomy = 'post_tag'; $args = array('include' => $ids); $terms = get_terms($taxonomy, $args);
In version 3.0, get_terms is returning an empty array :( I'm working on a plugin upgrade that needs to be backward compatible, so I'm hoping this change doesn't mean CSVs are invalid now.
Looks like a cut-and-paste error. Second $include should be $exclude.