WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The user needs to query posts by entering a $minPrice, $maxPrice and a category value.

Here is my query which returns no results:

function result() {

    $result = array(
        'cat'        => '10,17,18,13',
        'meta_query' => array(
                'key' => 'filter',
                'value' => array(  $min, $max ),
                'compare' => 'BETWEEN',
                'type' => 'numeric',

    // The Query
    $result = new WP_Query($result);
    // The Loop
    while ( $result->have_posts() ) : $result->the_post();
        include (ROCKABLE_INCLUDES . 'houseLandPackage-post-excerpt.php');

    // Reset Post Data

So problem is im not getting any results back when i use $min and $max as the meta query values. I will get the correct "min - max" results back when i use "300" and "400" however.

Here is what the url looks like when the query is submitted: http://localhost:8888/provgreen/?mode=advanced&min=3000&max=4000&s=+&cat=17&sa=Submit+Query

This thread states that the below code is needed for my query to work.: http://wordpress.org/support/topic/searching-for-posts-with-custom-data-in-a-numeric-range-price?replies=4

Any help or pointers much appreciated.

Here is the code i have in search.php



    if(isset($_GET["category"]) && $_GET["category"]!='') {
        $selectedCatId = get_term_by( 'slug', $selectedCategory, 'category' );
        $selectedCatId = $selectedCatId->term_id;

    if(isset($_GET["filter"])&& $_GET["filter"]!='') {
        $parts = explode("-",$selectedPrice);
        $min = $parts[0];
        $max = $parts[1];



this is in function.php

// Define the function that will create the join string
function mam_custom_field_range($filter='',$min=false,$max=false) {
  global $mam_global_join,$wpdb;
  if ($filter && ($min !== false || $max !== false)) {
    $mam_global_join =
      " JOIN $wpdb->postmeta acfr_$filter ON
      ( $wpdb->posts.ID = acfr_$filter.post_id
        AND acfr_$filter.meta_key = '$filter'";
    if ($min !== false) $mam_global_join .= " AND acfr_$filter.meta_value >= $min";
    if ($max !== false) $mam_global_join .= " AND acfr_$filter.meta_value <= $max";
    $mam_global_join .= ')';
// Define the join filter function
function mam_posts_join ($join) {
   global $mam_global_join;
   if ($mam_global_join) $join .= $mam_global_join;
   return $join;
// Add the filter to the hooks

im using

<?php wp_dropdown_categories(); ?>

and some input fields for the min, max values in form.php

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.