這是我的代碼。它從url獲取變量。它非常緩慢,有時甚至沒有完成。我該如何改進它?我的代碼速度慢,CPU佔用率高。如何改進?
注意:大部分時間一些變量不會有任何價值。我認爲,如果我檢查並從查詢中刪除它的數組,它會以某種方式改進它。
$value1 = $_GET['extra1'];
$value2 = $_GET['extra2'];
$value3 = $_GET['extra3'];
$value4 = $_GET['extra4'];
$value5 = $_GET['extra5'];
$value6 = $_GET['extra6'];
$value7 = $_GET['extra7'];
$value8 = $_GET['extra8'];
$value9 = $_GET['extra9'];
$value10 = $_GET['extra10'];
$args = array(
'meta_query' => array(
array(
'key' => extra1,
'value' => $value1,
'compare' => '='
),
array(
'key' => extra2,
'value' => $value2,
'compare' => '='
),
array(
'key' => extra3,
'value' => $value3,
'compare' => '='
),
array(
'key' => extra4,
'value' => $value4,
'compare' => '='
),
array(
'key' => extra5,
'value' => $value5,
'compare' => '='
),
array(
'key' => extra6,
'value' => $value6,
'compare' => '='
),
array(
'key' => extra7,
'value' => $value7,
'compare' => '='
),
array(
'key' => extra8,
'value' => $value8,
'compare' => '='
),
array(
'key' => extra9,
'value' => $value9,
'compare' => '='
),
array(
'key' => extra10,
'value' => $value10,
'compare' => '='
)
)
);
$query = new WP_Query($args);
if ($query->have_posts()) :
while ($query->have_posts()) : $query->the_post();
the_title();
endwhile;
endif;
謝謝你。它使它更快!它是否僅在具有值時才創建數組? (正如我所說的,大部分時間的某些值都是空的) – EnexoOnoma 2011-05-01 06:49:11