[wp-trac] [WordPress Trac] #34266: Support for ranges in WP_Query
WordPress Trac
noreply at wordpress.org
Mon Oct 12 16:58:08 UTC 2015
#34266: Support for ranges in WP_Query
-----------------------------+-----------------------------
Reporter: dziudek | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: trunk
Severity: normal | Keywords:
Focuses: |
-----------------------------+-----------------------------
Hello,
I think that WP_Query should support a very simple feature for all
comparable values - ranges.
I mean that WP_Query should support syntax like:
{{{
'post__in' => '123..678' // get posts with ID >= 123 and ID <= 678
}}}
It could use the BETWEEN keyword from MySQL. The BETWEEN keyword is just a
syntax feature which should behave as a normal comparing operators with
the similar performance (compare:
http://stackoverflow.com/questions/4382892/whats-mysqls-between-
performance-over).
Example implementation for the {{{post__in}}} parameter:
{{{
} elseif ( $q['post__in'] ) {
if ( is_string( $q['post__in'] ) ) {
$post__in = array_map( 'absint', explode('..', $q['post__in']));
$where .= " AND {$wpdb->posts}.ID BETWEEN {$post__in[0]} AND
{$post__in[1]}";
} else {
$post__in = implode(',', array_map( 'absint', $q['post__in'] ));
$where .= " AND {$wpdb->posts}.ID IN ($post__in)";
}
}
}}}
Optionally the following syntax could be also supported (but it will
increase amount of code necessary for parsing the new syntax):
{{{
'post__in' => '123..' // get posts with ID >= 123
'post__in' => '..123' // get posts with ID <= 123
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34266>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list