Home Optimize Wordpress Database Query
Reply: 0

Optimize Wordpress Database Query

KostasS
1#
KostasS Published in 2017-12-07 18:17:53Z

I have a wordpress template with custom post types and custom ACF fields.

i want to query custom WP post type using the custom fields below, it works but it is way to slow even with 100 records.

$caldate= $_GET['start'];   
    $currentdateday = $_GET['day'];
    $currentdate = date("Ymd", strtotime($caldate));        
    if($caldate==''){       
    $aArgs = array(
        'post_type'       => 'listing',
        'post_status'     => 'publish',
        'orderby'         => $atts['order_by'],
        'posts_per_page'  => $atts['posts_per_page']
    );

    }

      else if($caldate==$_GET['start'])
           {               
            $aArgs = array(
        'post_type'       => 'listing',
        'post_status'     => 'publish',
        'orderby'         => $atts['order_by'],
        'posts_per_page'  => $atts['posts_per_page'],   


        'meta_query' => array(  


              'relation' => 'OR',   

                array(  
                        'relation' => 'AND',
                    array(                  
                           'key' => 'iscalendar',
                           'value' => 1,
                           'compare' => '='
                            ), 
                    array(                  
                           'key' => 'isweek',
                           'value' => 0,
                           'compare' => '='
                            ),
                       array(
                              'key' => 'listingdate_0_eventstopdate',
                               'value' => $currentdate,
                               'compare' => '>=',
                               'type' => 'date'
                           ),
                      array(
                            'key' => 'listingdate_0_eventstartdate',
                               'value' => $currentdate,
                               'compare' => '<=',
                               'type' => 'date'
                           ), 

                    ),

                    array(  
                        'relation' => 'AND',
                      array(                    
                           'key' => 'iscalendar',
                           'value' => 0,
                           'compare' => '='
                            ), 
                    array(                  
                           'key' => 'isweek',
                           'value' => 1,
                           'compare' => '='
                            ),
                       array(                   
                           'key' => 'listingweek',
                           'value' => $currentdateday,
                           'compare' => 'LIKE'
                          ),    
                    ),

                    array(  
                        'relation' => 'AND',
                      array(                    
                           'key' => 'iscalendar',
                           'value' => 1,
                           'compare' => '='
                            ), 
                    array(                  
                           'key' => 'isweek',
                           'value' => 1,
                           'compare' => '='
                            ),
                       array(                   
                           'key' => 'listingweek',
                           'value' => $currentdateday,
                           'compare' => 'LIKE'
                          ),  
                      array(
                              'key' => 'listingdate_0_eventstopdate',
                               'value' => $currentdate,
                               'compare' => '>=',
                               'type' => 'date'
                           ),
                      array(
                            'key' => 'listingdate_0_eventstartdate',
                               'value' => $currentdate,
                               'compare' => '<=',
                               'type' => 'date'
                           ),                         
                    ),

                ),


            );                

    }

but it is way to slow to perform probably to so many keys...

is there a way to optimize the above query but to keep the logic the same?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299105 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO