在这里,我想为多个元键添加查询,如下所示:
$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过滤器
中的同一查询中使用多个meta_key答案 0 :(得分:3)
首先,您必须使用custom_posts_join
过滤器
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');
请告诉我这是否适合您!