[wp-trac] [WordPress Trac] #18736: Add REGEXP to 'compare' values in meta_query
WordPress Trac
wp-trac at lists.automattic.com
Wed Sep 21 15:39:51 UTC 2011
#18736: Add REGEXP to 'compare' values in meta_query
-------------------------+-----------------------------
Reporter: FlashUK | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Database | Version: 3.2.1
Severity: normal | Keywords:
-------------------------+-----------------------------
I wish to sort some queries using the alphabet.
My current query:
{{{
#!php
$getPostIds = $wpdb->get_col("
SELECT p.ID
FROM $wpdb->posts p, $wpdb->postmeta pm
WHERE p.ID = pm.post_id
AND pm.meta_key = 'prod-id'
AND pm.meta_value
REGEXP '^" . $wpdb->escape($alpha) . "'
AND p.post_status = 'publish'
AND p.post_type = 'review'
AND p.post_date < NOW()
ORDER BY pm.meta_value ASC"
);
$posts = new WP_Query(array(
'post__in' => $getPostIds,
'post_type' => 'review',
'post_status' => 'publish',
'showposts' => 20,
'paged' => $paged,
'caller_get_posts' => 1, // do not order sticky posts at the top
'orderby' => 'title',
'order' => 'ASC'
));
}}}
It would be much simpler if I could use the equivalent with meta_query:
{{{
#!php
query_posts(array(
'post_type' => 'review',
'post_status' => 'publish',
'showposts' => 20,
'paged' => $paged,
'caller_get_posts' => 1, // do not order sticky posts at the top
'orderby' => 'metal_value',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'prod-id',
'value' => '^'.get_query_var('letter'),
'compare' => 'REGEXP'
)
)
));
}}}
I'd love to see it implemented :)
Thanks!
--
Ticket URL: <http://core.trac.wordpress.org/ticket/18736>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list