-1

I have a custom loop to display a custom post type 'properties' . The idea is to search properties based on different search parameters selected by users. Now the weird problem I am facing is that if the number of the search parameters increases to 7 the WP_Query doesn't return any results at all.

The properties with these search parameters exsit in the WP Backend . If I remove any of the one search parameter to make it less than 7 it displays the results. But as soon the number of parameters goes up it wont display any result.

What I am doing wrong ?

Here is the meta query array:

(
[0] => Array
    (
        [key] => payment_status
        [value] => yes
    )

[1] => Array
    (
        [key] => expired
        [value] => no
    )

[2] => Array
    (
        [key] => listing_type
        [meta_value_num] => Array
            (
                [0] => 1
                [1] => 2
                [2] => 3
            )

    )

[3] => Array
    (
        [key] => available_for
        [value] => sale
    )

[4] => Array
    (
        [key] => country
        [value] => Saudi Arabia
    )

[5] => Array
    (
        [key] => city
        [value] => Riyadh
    )

[6] => Array
    (
        [key] => property_type
        [value] => land
    )

[7] => Array
    (
        [key] => by
        [value] => owner
    )

)

As I said if I remove any of the parameters the results will display. Here is my WP_Query function

$loop = new WP_Query( 
                                        array( 
                                              'post_type' => 'properties', 
                                              'posts_per_page' => (int)get_field(ICL_LANGUAGE_CODE.'_search_results_per_page',get_active_lang_id()),
                                                'meta_query' => $meta_query,
                                                'orderby' => 'date',
                                                'order' => 'DESC' ,
                                                'paged' =>$paged
                                              )); 

Is it a known problem with WP_Query that it doesn't display posts with large meta_query set?

Any help would be appreciated

Ahmar

2
  • I think one of your query not satisfying the condition. Which condition you have removed to make the query run? The last condition 'by owner'? Commented May 20, 2016 at 7:47
  • 2
    The way to coding nirvana is to always blame your code first ;) Your code is most likely to be blamed but it will be impossible to guess how without actually more information especially about what is in the DB. One thing you can do is to print the query being generated by the wp_query object and run it directly at phpmyadmin and check for errors/surprising results. Keep in mind that the main job of wp_query is to generate the SQL query, communicating with the DB and bringing the results are just to make life easier, but are unlikely to do anything surprising by themselves. Commented May 20, 2016 at 8:11

3 Answers 3

0

I think one of your query not satisfying the condition. Which condition you have removed to make the query run? The last condition 'by owner'? If so, try the following meta_query

If something wrong with the condition change the relation of the query from AND to OR and check (Refer). Also echo your query and run in PHPMyAdmin to make sure that there is no error with your query.

$meta_query = array(
        array(
            'key'     => 'payment_status',
            'value'   => 'yes',
        ),
array(
            'key'     => 'expired',
            'value'   => 'no',
        ),
array(
            'key'     => 'listing_type',
            'meta_value_num'   => array(1,2,3),
        ),
array(
            'key'     => 'available_for',
            'value'   => 'sale',
        ),
array(
            'key'     => 'country',
            'value'   => 'Saudi Arabia',
        ),
array(
            'key'     => 'city',
            'value'   => 'Riyadh',
        ),
array(
            'key'     => 'property_type',
            'value'   => 'land',
        ),
                array(
                        'relation' => 'OR',
                        array(
                                'key' => 'by',
                                'value' => 'owner',
                        ),
        ),
);
0

Adding to the other answer (try checking directly in PHPMyAdmin), please check if you can simplify the query. If you do so many Meta_queries, the Postmeta Table is joined on every single Meta field, which can easily overtax your MySQL-Server (had this problem myself).

If you need to do this many meta_field Queries in one go, you can try to make seperate calls and insert the found post_ids into the main query for instance.

0

Make sure that you're doing enough with the relations if using AND are you sure that those values exist in the record, try playing with OR.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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