sql - Complex query with WP_Query -
i still learning wordpress , trying perform query of posts wp_query, meta_query precise, thing after trying different possible ways , finding out can't nest arrays relations dont know if next possible way make sql query directly.
to better explain do, next array help:
'meta_query' => array( 'relation' => 'and', array( 'key' => 'meta_geo', 'value' => '46', 'compare' => '=', ), array( 'key' => 'meta_dest', 'value' => 'si', 'compare' => '=', ), array( 'relation' => 'or', array( array( 'key' => 'meta_1', 'value' => '10', 'compare' => '<=', ), array( 'key' => 'meta_1', 'value' => '30', 'compare' => '>=', ) ), array( 'relation' => 'or', array( 'key' => 'meta_1', 'value' => '', 'compare' => '=', ), array( 'key' => 'meta_1', 'value' => '', 'compare' => '=', ) ) ) ),
many time, if there expertet can give me hint grateful.
sorry english.
based on have above below closest going get...
'meta_query' => array( 'relation' => 'or', array( 'key' => 'meta_geo', 'value' => '46', 'compare' => '=', ), array( 'key' => 'meta_dest', 'value' => 'si', 'compare' => '=', ), array( 'key' => 'meta_1', 'value' => array('10','11','12' etc), 'compare' => 'in', ), )
this leave little sorting out however. can done loop , display results of query using loop can use that.
e.g.
while ( $my_query->have_posts() ) : $my_query->the_post(); $metavalue = get_post_meta($post->id, 'meta_geo', true); $metavalue = get_post_meta($post->id, 'meta_dist', true);// if there lot of conds, use get_post_meta($post->id) return object of value arrays if($metavalue == 46 && ): //proceed //html here! endif; endwhile;
Comments
Post a Comment