If the price is stored as a custom field you\'ll need to use the meta_query
argument of WP_Query
(see Codex). For instance:
//Get posts with custom field \'price\' between 20 and 100
$price_filtered = WP_Query(array(
\'meta_query\'=>array(
array(
\'key\' => \'price\',
\'value\' => array( 20, 100 ),
\'type\' => \'numeric\',
\'compare\' => \'BETWEEN\'
),
)
));
(where price
is the key of the custom field). Depending on how you might be implementing this (is it intended to be the \'main query\' or not - you might want to use this at pre_get_posts
)
Edit
If filtering a search result:
add_action(\'pre_get_posts\', \'wpse71814_filter_search\');
function wpse71814_filter_search( $query ){
if( $query->is_search() && isset($_GET[\'min\']) ){
//Collect user input from $_GET for example
$user_input_min_value = $_GET[\'min\'];
$meta_query = $query->get(\'meta_query\');
$meta_query[] = array(
\'key\' => \'price\',
\'value\' => $user_input_min_value,
\'type\' => \'NUMERIC\',
\'compare\' => \'>=\'
);
$query->set(\'meta_query\',$meta_query);
}
}
Note: The original answer had a meta query which specified a range. The second answer has a meta query which filters for prices above some minimum value.
Usage: /?s=keyword&min=300