Home › Forums › Front-end Issues › Custom query with Between and Like (3 params)
Hello,
I created a custom loop with 3 params. 1 range minprice / maxprice + one select. I don’t why since I add the third params no post appear.
<?php
// set up or arguments for our custom query
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'cat' => $cat,
'post_type' => 'post',
'posts_per_page' => 28,
'paged' => $paged,
'meta_query' => array(
array(
'key' => 'prix',
'type' => 'NUMERIC',
'value' => array($minprice, $maxprice),
'compare' => 'BETWEEN'
),
array(
'key' => 'genre',
'value' => $genre,
'compare' => 'LIKE'
)
)
);
// create a new instance of WP_Query
$the_query = new WP_Query($args);
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // run the loop ?>
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content-category', get_post_format() );
?>
<?php endwhile; ?>
<?php if ($the_query->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?>
<div class="clearfix"></div>
<?php bootstrap_pagination();?>
<?php } ?>
<?php else: ?>
<?php get_template_part( 'no-results', 'archive' ); ?>
<?php endif; ?>
</div>
<?php wp_reset_query();
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
if ($page ==1) { echo category_description ( get_category_by_slug ( 'category-slug' )-> term_id );
} ?>
If I remove this part
array(
'key' => 'genre',
'value' => $genre,
'compare' => 'LIKE'
)
Query show post. But if I add this part post don’t appear… “genre” field is a checkbox with value “femme” / “homme” / “couple” / “adolescent” / “enfant”.
How to fix this ?
Hi @wecandoit
Could you please make sure that the $genre
variable has the correct value? Could you please debug it like this:
var_dump($genre)
Also, could you please add the value manually like this:
array(
'key' => 'genre',
'value' => 'femme',
'compare' => 'LIKE'
)
Thanks 🙂
The topic ‘Custom query with Between and Like (3 params)’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.