A
A
Alex86102018-04-01 22:49:29
WordPress
Alex8610, 2018-04-01 22:49:29

How to sort/filter a field by custom fields?

Interested in how you can sort posts by arbitrary fields ("city" and "rating").
Ideally, the filter should consist of two select lists: city selection and sorting by rating.
Example:
5ac1366e93efc452631589.jpeg
I suspect that you need to somehow add the $_GET function and something from this opera:
$args = array(
'meta_key' => 'color',
'meta_value' => 'blue'
);
$query = new WP_Query( $args );
But I can’t figure out how to connect it or insert it into the form of the mind:

<form class='post-filters'>
<select name="select_city">
        <?php ?>
    </select>
<select name="order_by_rating">
        <?php ?>
    </select>
    <input type='submit' value='Filter!'>
</form>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question