1

I have a rather huge meta_query here and it hangs at execution: browser just won't load the page, it goes on loading ...

As far as I know this should work after WP 4.1 (I have it). Also tried updating to 4.2 to no avail.

Am I doing something terribly wrong here or is the query just too heavy?

Thanks for any info.

$meta_query = array(
'relation' => 'AND',

// IF $level GIVEN
array(
    'relation' => 'OR',
    array(
        'key' => 'co_level',                 
        'value' => $level,                  
        'compare' => 'IN'   
    ),
    array(
        'relation' => 'AND',
        array(
            'key' => 'co_program2',
            'value' => $program_ids,
            'compare' => 'IN'
        ),
        array(
            'key' => 'co_level2',                 
            'value' => $level,                  
            'compare' => 'IN'   
        ),

    ),
    array(
        'relation' => 'AND',
        array(
            'key' => 'co_program3',
            'value' => $program_ids,
            'compare' => 'IN'
        ),
        array(
            'key' => 'co_level3',                 
            'value' => $level,                  
            'compare' => 'IN'   
        ),
    ),             

),

// IF $year GIVEN
array(
    'relation' => 'OR',
    array(
        'key' => 'co_year', 
        'value' => $year, 
        'compare' => 'IN'
    ),
    array(
        'relation' => 'AND',
        array(
            'key' => 'co_program2',
            'value' => $program_ids,
            'compare' => 'IN'
        ),
        array(
            'key' => 'co_year2', 
            'value' => $year, 
            'compare' => 'IN'
        ),
    ),  
    array(
        'relation' => 'AND',
        array(
            'key' => 'co_program3',
            'value' => $program_ids,
            'compare' => 'IN'
        ),
        array(
            'key' => 'co_year3', 
            'value' => $year, 
            'compare' => 'IN'
        ),
    ),
),  
);

$args = array( 
'post_type' => 'course',
'posts_per_page' => -1,             // get all posts

'orderby' => array('meta_value_num'=>'ASC','menu_order'=>'ASC'),        // order by given meta value AND menu_order
'meta_key' => $meta_key_orderby,
'order' => 'ASC',

'meta_query' => $meta_query,

);  
4
  • 2
    Nested meta queries works since WP 4.1 (anyway, you should update to WP 4.2, it fixes security risks). You could try to reduce the meta query based on conditions. For example, you have meta queries if $year is given, but you are always including the meta query for year conditions; what if $year is not given? Same for the other conditions. Do the complexity of the query and the narrow context we can see in the question, I can not tell you anything else without a closer debug in your application.
    – cybmeta
    May 15, 2015 at 7:03
  • Even smaller nested query did not work. It loads forever.. This one here has no conditions to allow certain variables, since I know in this case they are given. Can you give me an example where nested query should work? For instance by reducing my query alot? I'm thinking there should be something wrong ..
    – trainoasis
    May 15, 2015 at 10:54
  • Definetily there is something wrong we can not see in your code. Provide a full example that can be used to reproduce the issue, otherwise we can not help you. As I said, I think a closer look to your application may be needed.
    – cybmeta
    May 15, 2015 at 13:28
  • Thanks, unfortunately I cannot provide a closer look into my app. Will try to find more about this nesting error and why even the small nested one does not work.
    – trainoasis
    May 18, 2015 at 12:13

0

Your Answer

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

Browse other questions tagged or ask your own question.