Hey i have a problem this my code and if i used with all parameters i get from $_GET its start work so slowly..... (like 5 min).
$checkbox = array(
'immediate'=>'כניסה מידית',
'air'=>'מיזוג',
'furniture'=>'ריהוט',
'renovated'=>'משופץ',
'elevator'=>'מעלית',
'parking'=>'חניה'
);
if($_GET['mainCat']>0){$cat = array(array('taxonomy' => 'category-board', 'field' => 'term_id','terms' => $_GET['mainCat']));}
if($_GET['fromNumberOfRooms']>0){$fromNumberOfRooms = array('key' => 'number-of-rooms','value' => $_GET['fromNumberOfRooms'],'compare' => '>=', 'type' => 'NUMERIC');}
if($_GET['upToNumberOfRooms']>0){$upToNumberOfRooms = array('key' => 'number-of-rooms','value' => $_GET['upToNumberOfRooms'],'compare' => '>=', 'type' => 'NUMERIC');}
if($_GET['fromSize']>0){$fromSize = array('key' => 'size','value' => $_GET['fromSize'],'compare' => '>=', 'type' => 'NUMERIC');}
if($_GET['upToSize']>0){$upToSize = array('key' => 'size','value' => $_GET['upToSize'],'compare' => '<=', 'type' => 'NUMERIC');}
if($_GET['fromPrice']>0){$fromPrice = array('key' => 'price','value' => $_GET['fromPrice'],'compare' => '>=', 'type' => 'NUMERIC');}
if($_GET['upToPrice']>0){$upToPrice = array('key' => 'price','value' => $_GET['upToPrice'],'compare' => '<=', 'type' => 'NUMERIC');}
foreach($checkbox as $key=>$val) {
if ($_GET[$key] >= 1) {
$$key = array('key' => $key, 'value' => $_GET[$key], 'compare' => '>=', 'type' => 'NUMERIC');
}
}
*/
$args = array(
'post_type' => 'board', 'tax_query' => $cat,
'meta_query' => array($fromPrice, $upToPrice, $fromSize, $upToSize, $fromNumberOfRooms, $upToNumberOfRooms, $immediate, $air, $furniture, $renovated, $elevator, $parking)
);
query_posts( $args );
Hey i have a problem this my code and if i used with all parameters i get from $_GET its start work so slowly..... (like 5 min).
$checkbox = array(
'immediate'=>'כניסה מידית',
'air'=>'מיזוג',
'furniture'=>'ריהוט',
'renovated'=>'משופץ',
'elevator'=>'מעלית',
'parking'=>'חניה'
);
if($_GET['mainCat']>0){$cat = array(array('taxonomy' => 'category-board', 'field' => 'term_id','terms' => $_GET['mainCat']));}
if($_GET['fromNumberOfRooms']>0){$fromNumberOfRooms = array('key' => 'number-of-rooms','value' => $_GET['fromNumberOfRooms'],'compare' => '>=', 'type' => 'NUMERIC');}
if($_GET['upToNumberOfRooms']>0){$upToNumberOfRooms = array('key' => 'number-of-rooms','value' => $_GET['upToNumberOfRooms'],'compare' => '>=', 'type' => 'NUMERIC');}
if($_GET['fromSize']>0){$fromSize = array('key' => 'size','value' => $_GET['fromSize'],'compare' => '>=', 'type' => 'NUMERIC');}
if($_GET['upToSize']>0){$upToSize = array('key' => 'size','value' => $_GET['upToSize'],'compare' => '<=', 'type' => 'NUMERIC');}
if($_GET['fromPrice']>0){$fromPrice = array('key' => 'price','value' => $_GET['fromPrice'],'compare' => '>=', 'type' => 'NUMERIC');}
if($_GET['upToPrice']>0){$upToPrice = array('key' => 'price','value' => $_GET['upToPrice'],'compare' => '<=', 'type' => 'NUMERIC');}
foreach($checkbox as $key=>$val) {
if ($_GET[$key] >= 1) {
$$key = array('key' => $key, 'value' => $_GET[$key], 'compare' => '>=', 'type' => 'NUMERIC');
}
}
*/
$args = array(
'post_type' => 'board', 'tax_query' => $cat,
'meta_query' => array($fromPrice, $upToPrice, $fromSize, $upToSize, $fromNumberOfRooms, $upToNumberOfRooms, $immediate, $air, $furniture, $renovated, $elevator, $parking)
);
query_posts( $args );
Share
Improve this question
asked Oct 6, 2015 at 12:33
Mr.SmithMr.Smith
11 bronze badge
4
|
1 Answer
Reset to default 1When you have a few thousand entries and use post_type
in combination with meta values, the MySQL query starts running very, very slowly because it seems to do a full table scan on the wp_postmeta
table. The most direct solution is to add an index on the wp_postmeta
table to avoid the full scan.
This is the SQL to add the index:
ALTER TABLE `wp_postmeta` ADD INDEX `key_value` (`meta_key`(20), `meta_value`(20)) USING BTREE;
The speed improvement was somewhere around 100x. I needed the first twenty characters of each field -- you could alter it to be more or less.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745430392a4627363.html
query_posts()
- ever. – Nicolai Grossherr Commented Oct 6, 2015 at 12:40'fields => 'ids'
, of course only if that is applicable for you. Furthermore, I'm guessing you have a lot of database entries, if not your problem has another origin. Generally your database can be very big, but then you server has to be powerful. – Nicolai Grossherr Commented Oct 7, 2015 at 8:58