You can add more than one filter call, so each of your custom meta_key
‘s can be handled in separate code and when executed will cumulatively adjust the query.
Perhaps look at the pre_get_posts
filter rather than parse_query
(although the solution I’m suggesting could possibly work in either case). pre_get_posts
gives you access to the current query before it is executed by WordPress, and you will limit the posts that the query will fetch from the database.
I haven’t tested this code: it’s just an edit here against your code to show you how you could approach this (so please check the syntax for errors).
You’d end up with something like this:
add_filter('pre_get_posts', 'wpse45436_property_baths_posts_filter');
function wpse45436_property_baths_posts_filter( $query ){
global $pagenow;
$type="property";
if (isset($_GET['post_type'])) {
$type = $_GET['post_type'];
}
if ( 'property' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['property_baths']) && $_GET['property_baths'] != '') {
$query->query_vars['meta_key'] = 'property_baths';
$query->query_vars['meta_value'] = $_GET['property_baths'];
}
}
add_filter('pre_get_posts', 'wpse45436_property_beds_posts_filter');
function wpse45436_property_beds_posts_filter( $query ){
global $pagenow;
$type="property";
if (isset($_GET['post_type'])) {
$type = $_GET['post_type'];
}
if ( 'property' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['property_beds']) && $_GET['property_beds'] != '') {
$query->query_vars['meta_key'] = 'property_beds';
$query->query_vars['meta_value'] = $_GET['property_beds'];
}
}
Check the Codex for further details on the pre_get_posts
filter