Forums › Forums › Search & Filter Pro › WP_Query with meta_query with two clause and Search&Filter Pro
- This topic has 4 replies, 2 voices, and was last updated 6 years, 6 months ago by
Anonymous.
-
Anonymous(Private) October 25, 2018 at 3:08 pm #191847
I have custom post type job, which has one custom field chceckbox named top_job and it has only one choice Top job. There will be always only one Top job.
I need to display this one top job always on first place (it has different grid size and styling) and the rest of jobs after that.
I need to have only one while because I am using Search&Filter Pro plugin to filtering taxonomies – job type, area, city.
I have this:
$args = array( 'search_filter_id' => 435, 'post_type' => array('job'), 'post_status' => array('publish'), 'posts_per_page' => '-1', 'meta_query' => array( 'relation' => 'OR', 'topjob_clause' => array ( 'key' => 'top_job', 'value' => '"topjob"', 'compare' => 'LIKE' ), 'normaljob_clause' => array ( 'key' => 'top_job', 'value' => '"topjob"', 'compare' => 'NOT LIKE' ) ), 'orderby' => array( 'topjob_clause' => 'DESC', 'normaljob_clause' => 'DESC' ), ); $query = new WP_Query( $args ); if ( $query->have_posts() ) : ?> <div class="o-layout__item u-1/1"> <?php echo do_shortcode('[searchandfilter id="435"]') ?> </div> <div class="job__filter"> <?php while ( $query->have_posts() ) : $query->the_post(); get_template_part('parts/list', 'job'); endwhile; ?> </div> <?php else : _e('Sorry, there are no jobs yet.', 'lpw'); endif; wp_reset_postdata();
Orderby is fully ignored by the plugin. When I disable ‘search_filter_id’ => 435, in $args, orderby works like a charm …
I don’t know where is the problem. Is the problem in my query or the plugin just don’t work with clauses?
Trevor(Private) October 25, 2018 at 3:20 pm #191854You need to use our Edit Query Arguments filter instead:
https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments
-
AuthorPosts