[wp-hackers] meta_value contains text

Ashok Padda ashok.padda at gmail.com
Sun Aug 16 21:06:48 UTC 2009


@ Scribu,

Thank you, for pointing us in the right direction. Though, posts_where is
updating the where condition we also need to join wp_postmeta table, here.
So, I think we need to add posts_join filter, too. Please correct me if I'm
wrong.

@ Jorn,

Following plugin worked for me.
-----------------------------x-----------------------------
$my_metavalue = 'blue sky';
add_filter('posts_join', 'my_join');
add_filter('posts_where', 'my_where');

function my_join( $join ) {
  global $wpdb;
  $join .= " LEFT JOIN " .$wpdb->postmeta. " ON " .$wpdb->posts. ".ID="
.$wpdb->postmeta. ".POST_ID";
  return $join;
}

function my_where( $where ) {
  global $my_metavalue;
  $where .= " and meta_value like '" .$my_metavalue. "'";
  return $where;
}
-----------------------------x-----------------------------

+Ashok

On Mon, Aug 17, 2009 at 12:39 AM, scribu <scribu at gmail.com> wrote:

> Or, instead of hacking a core file, you could use the 'posts_where' filter
> and add a condition like:
>
> AND meta_value LIKE('New%');
>
> --
> http://scribu.net
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list