-1

I have problem with my WP_Query, I want to display results with my custom query, I'm using Advanced Custom Fields

<?php
// Get data from URL into variables
$miejscowosc = $_GET['miejscowosc'] != '' ? $_GET['miejscowosc'] : '';
$typ_nieruchomosci = $_GET['typ_nieruchomosci'] != '' ? $_GET['typ_nieruchomosci'] : '';
$min = $_GET['price'];
$max = $_GET['price-max'];
//var_dump($typ_nieruchomosci);
// Start the Query
//var_dump($min);
$price = explode('zł -', $min);
$min_1 = preg_replace("/[^0-9]/", "",$price[0]);
$max_1 = preg_replace("/[^0-9]/", "",$price[1]);
$value = array($min_1, $max_1);
$v_args = array(
        'post_type'     =>  'post', // your CPT
      //  's'             =>  $_name, // looks into everything with the keyword from your 'name field'
        'meta_query'    =>  array(
                                array(
                                    'key'     => 'typ_nieruchomosci', // assumed your meta_key is 'car_model'
                                    'value'   => $typ_nieruchomosci,
                                    'compare' => 'LIKE', // finds models that matches 'model' from the select field
                                ),
                                array(
                                    'key'   => 'test',
                                    'value' => $miejscowosc,
                                    'compare'   => 'LIKE',
                                ),
                                array(
                                    'key'   => 'cena_nieruchomości',
                                    'value' => $value,
                                    'type'  => 'NUMERIC',
                                    'compare'   => 'BETWEEN',

                                ),
                            )
    );
$houseQuery = new WP_Query( $v_args );
?>

If I have something like this, my WP_Query not return any results, and if I have something like this:

<?php
// Get data from URL into variables
$miejscowosc = $_GET['miejscowosc'] != '' ? $_GET['miejscowosc'] : '';
$typ_nieruchomosci = $_GET['typ_nieruchomosci'] != '' ? $_GET['typ_nieruchomosci'] : '';
$min = $_GET['price'];
$max = $_GET['price-max'];
//var_dump($typ_nieruchomosci);
// Start the Query
//var_dump($min);
$price = explode('zł -', $min);
$min_1 = preg_replace("/[^0-9]/", "",$price[0]);
$max_1 = preg_replace("/[^0-9]/", "",$price[1]);
$value = array($min_1, $max_1);
$v_args = array(
        'post_type'     =>  'post', // your CPT
      //  's'             =>  $_name, // looks into everything with the keyword from your 'name field'
        'meta_query'    =>  array(
                                array(
                                    'key'     => 'typ_nieruchomosci', // assumed your meta_key is 'car_model'
                                    'value'   => $typ_nieruchomosci,
                                    'compare' => 'LIKE', // finds models that matches 'model' from the select field
                                ),
                                array(
                                    'key'   => 'test',
                                    'value' => $miejscowosc,
                                    'compare'   => 'LIKE',
                                ),
                                array(
                                    'key'   => 'cena_nieruchomości',
                                    'value' => array(20000, 50000),
                                    'type'  => 'NUMERIC',
                                    'compare'   => 'BETWEEN',

                                ),
                            )
    );
$houseQuery = new WP_Query( $v_args );
?>

This returning me my result, what is wrong with my "cena_nieruchomosci" key? I can not use variables in array?

  • Ok, I fixed it. Topic can be close. – Jakub Jóźwiak May 23 '17 at 6:42
  • 1
    A sign of good manners could be to explain how did you fix the problem. This site is a knowledge base. – Max Yudin May 23 '17 at 6:47
  • I changed my min and max value to int $value = array(intval($min_1), intval($max_1)); – Jakub Jóźwiak May 23 '17 at 11:00
0

if you print_r($houseQuery), what is your request query? It's a correct SQL query?

When you print WP_Query object you can find this in structure: [request] => SELECT SQL_CALC_FOUND_ROWS[...]

You need to analyze this to understand what's going on.

Let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.