admin管理员组

文章数量:1394065

I'm trying to search in two different post_type "places" and "events" but one parameter is about dates and places don't have this meta.

Also, event got 4 different dates : a start_date and end_date AND start_date_publish and end_date_publish who's here for determinate the moment when the event can be display on the site or on the search form results.

How can i make this query more light for searching on this two post type in one time ?

Here is the code that crashed the query because it's taking too much time to search :

(PS. Sry for this bad english)

array_push($meta_query_array, array(
            'relation' => 'OR', 
            array(
                array(
                    'key' => 'start_date', 
                    'compare' => 'NOT EXISTS',
                    'value' => ''
                ),
                array(
                    'key' => 'end_date', 
                    'compare' => 'NOT EXISTS',
                    'value' => ''
                ),
                array(
                    'key' => 'start_date_publish',
                    'compare' => 'NOT EXISTS',
                    'value' => ''
                ), 
                array(
                    'key' => 'end_date_publish', 
                    'compare' => 'NOT EXISTS',
                    'value' => ''
                )

            ), 
            array(
            'relation' => 'AND', 
                array(
                    'key' => 'start_date',
                    'value' => $current_date,
                    'type' => 'DATE',
                    'compare' => '<='
                ),
                array(
                    'key' => 'end_date',
                    'value' => $current_date,
                    'type' => 'DATE',
                    'compare' => '>='
                ),
                array(
                    'key' => 'start_date_publish',
                    'value' => $current_date,
                    'type' => 'DATE',
                    'compare' => '<='
                ),
                array(
                    'key' => 'end_date_publish',
                    'value' => $current_date,
                    'type' => 'DATE',
                    'compare' => '>='
                ),
            )
        ));

本文标签: Heavy meta query causing SQL crash