0

在这里,我想为多个元键添加查询,如下所示:

$where .= " AND meta_key='order_assign_delivery_date' AND meta_value LIKE '0000%' And meta_key='order_assign_data' AND meta_value=0";

那么现在该怎么做呢?

上面的查询不起作用,这很明显

请指导我如何在 posts_where 过滤器的同一查询中使用多个元键

4

1 回答 1

4

custom_posts_join首先,您必须使用过滤器设置两个 postmeta

function custom_posts_join($join){
 global $wpdb;
 $join .= " LEFT JOIN $wpdb->postmeta as meta_1 ON $wpdb->posts.ID = meta_1.post_id LEFT JOIN $wpdb->postmeta as meta_2 ON $wpdb->posts.ID = meta_2.post_id";
 return $join;
}
add_filter( 'posts_join' , 'custom_posts_join');

然后你现在可以设置 posts_where

function filter_where( $where = '' ) {
       $where .= " AND meta_1.meta_key='order_assign_delivery_date' AND meta_1.meta_value LIKE '0000%' And meta_2.meta_key='order_assign_data' AND meta_2.meta_value=0";
}
add_filter('posts_where', 'filter_where');

让我知道这是否适合您!

于 2013-10-11T07:25:16.120 回答