Answer the question
In order to leave comments, you need to log in
How to sort posts by acf field in query_posts from largest to smallest?
Hello! If I have 2 buttons "cheaper" and "more expensive"
<form action="" method="get" >
<div class="right">
<ul>
<li>Сортировать:</li>
<label class="radio_1">
<input type="radio" name="filter2" value="minimal_price" id="">
<li>Дешевле</li>
</label>
<label class="radio_2">
<input type="radio" name="filter2" value="maximum_price" id="">
<li>Дороже</li>
</label>
</ul>
</div>
<button>го2</button>
</form>
<?php
$query = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => 6,
'meta_query' => array(
'max_price' => array(
'key' => 'цена',
'value' => $max_price,
'type' => 'NUMERIC',
'compare' => '<=',
),
'min_price' => array(
'key' => 'цена',
'value' => $min_price,
'type' => 'NUMERIC',
'compare' => '>=',
),
),
'orderby' => 'max_price,min_price',
) );
?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<?php
get_template_part( 'loop/item_type1', 'loop' );
?>
<?php endwhile; ?>
<?php
wp_reset_query();
?>
Answer the question
In order to leave comments, you need to log in
'orderby' => 'meta_value_num',
'meta_key' => 'цена',
'order' => 'DESC'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question