Very slow WP_Query request
-
Hello everyone.
I’m creating a website for a real estate company and to allow people to search for houses and flats, there is a search engine with this fields : maximum price, minimum area, typology, locations, delivery date and type of dwelling.
I use Custom Post Type UI and Advanced Custom Fields PRO.
Here is my code for the query :
$prix = !empty($_POST['prix']) ? $_POST['prix'] : 9999999; $superficie = !empty($_POST['superficie']) ? $_POST['superficie'] : 0; $type_logement = !empty($_POST['type_logement']) ? $_POST['type_logement'] : ''; $typologie = !empty($_POST['typologie']) ? $_POST['typologie'] : ''; $lieux = !empty($_POST['lieux']) ? $_POST['lieux'] : ''; $date = !empty($_POST['date']) ? $_POST['date'] : ''; if(!empty($_POST)) { $args = array( 'numberposts' => -1, 'post_type' => array('bien-immobilier'), 'post_status' => 'publish', 'fields' => 'ids', 'orderby' => 'date', 'order' => 'DESC', 'meta_query' => [ 'relation' => 'AND', array( 'key' => 'type_logement', 'value' => $type_logement, 'compare' => 'LIKE', ), array( 'key' => 'typologie', 'value' => $typologie, 'compare' => 'LIKE', ), array( 'relation' => 'AND', array( 'relation' => 'OR', array( 'key' => 'lieu', 'value' => $lieux, 'compare' => 'LIKE', ), array( 'key' => 'departement', 'value' => $lieux, 'compare' => 'LIKE', ), ), ), array( 'key' => 'prix', 'value' => $prix, 'type' => 'NUMERIC', 'compare' => '<=' ), array( 'key' => 'superficie', 'value' => $superficie, 'type' => 'NUMERIC', 'compare' => '>=' ), array( 'key' => 'annee_livraison', 'value' => $date, 'type' => 'NUMERIC', 'compare' => '<=' ), ], ); $produits = new WP_Query($args); }else{ $args = array( 'posts_per_page' => 12, 'post_type' => array('bien-immobilier'), 'post_status' => 'publish', 'orderby' => 'date', 'fields' => 'ids', 'order' => 'DESC' ); $produits = new WP_Query($args); }
I don’t understand why this request is very slow (10-15 seconds). There are like 30 products in total for the moment in database. And if I just comment the price (“Prix”) part, it’s faster.
It’s not the display of products that is slow, because even when I comment everything except the query, it’s still slow.
Could you help me, please ? Thanks !
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Very slow WP_Query request’ is closed to new replies.