[wp-trac] [WordPress Trac] #11482: Add LIKE to meta_compare

WordPress Trac wp-trac at lists.automattic.com
Fri Dec 18 19:02:01 UTC 2009


#11482: Add LIKE to meta_compare
-------------------------+--------------------------------------------------
 Reporter:  joehoyle     |       Owner:  ryan     
     Type:  enhancement  |      Status:  new      
 Priority:  normal       |   Milestone:  3.0      
Component:  Query        |     Version:  2.9      
 Severity:  normal       |    Keywords:  has-patch
-------------------------+--------------------------------------------------

Comment(by Denis-de-Bernardy):

 Replying to [comment:4 joehoyle]:
 > In terms of not doing it in favour of using posts_join, I feel is a bit
 of a workaround, hooking into posts_join, checking if the join has been
 added, then hooking into posts_where and inserting the LIKE statement
 seems like a lot of work compared to a proper implementation of using LIKE
 as a meta_compare. Especially as currently the posts_join and posts_where
 filters don't give you access to the WP_Query object it is a pain to check
 for query vars etc (global $wp_query not included).

 Just in case you're not aware that you can put AND clauses in a JOIN
 statement, your example would be:

 {{{
 JOIN $wpdb->postmeta as my_plugin_meta
 ON my_plugin_meta.post_id = $wpdb->posts.ID
 AND my_plugin_meta.meta_key = 'url'
 AND my_plugin_meta.meta_value LIKE '$my_sanitized_like_statement'
 }}}

 you can check the WP query in your plugin's function:

 {{{
 function posts_join($join) {
   global $wp_query;
   global $wp_the_query;
   # ignore if it's not the main loop
   if ( $wp_query !== $wp_the_query )
     return $join;

   // do stuff...
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/11482#comment:5>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list