Skip to content

@Viper007Bond /gist:1325696
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Limit results to post meta via URL
<?php
add_action( 'pre_get_posts', 'oomskaap_price_range_limiter' );
function oomskaap_price_range_limiter( $query ) {
// Only do something if both the start and end values are set in the URL
if ( empty( $_GET['pricestart'] ) || empty( $_GET['priceend'] ) )
return;
// Only modify the main query
// 3.3 adds "is_main_query"
if ( method_exists( $query, 'is_main_query' ) ) {
if ( ! $query->is_main_query() ) {
return;
}
}
// Pre-3.3
else {
global $wp_the_query;
if ( $query !== $wp_the_query ) {
return;
}
}
// Validate/sanitize
$start = absint( $_GET['pricestart'] );
$end = absint( $_GET['priceend'] );
// Add in some more query arguments
$query->query_vars['meta_query'][] = array(
'key' => 'price',
'value' => array( $start, $end ),
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.