Hi!
I’m filtering posts, and in my regions filter I have option “All”, but all is of course not in field choice list.
So when I select all in regions filter, all posts should be listed no meter in which region they fit.
This is my code:
<?php
$region = $_GET["regions"];
$gender = $_GET["gender"];
global $wp_query;
$args = array_merge(
$wp_query->query_vars,
array(
'meta_query' => array(
array(
'key' => 'select_region',
'value' => $region,
'compare' => 'LIKE'
),
array(
'key' => 'gender',
'value' => $gender
),
)
)
);
query_posts( $args );
?>
I searched on forum, but I could not find solution.
Any ideas?
Thanks!
You need to dynamically generate your meta query based on the value submitted.
<?php
$region = $_GET["regions"];
$gender = $_GET["gender"];
global $wp_query;
$meta_query = array();
if ($region != 'all') {
$meta_query[] = array(
'key' => 'select_region',
'value' => $region,
'compare' => 'LIKE'
)
}
// .. do something similar for the other meta query parameters
$args = array_merge(
$wp_query->query_vars,
array(
'meta_query' => $meta_query;
)
);
query_posts( $args );
?>
Thanks, this is what I needed 🙂