2013-02-23 64 views
0

我在我的一个网页上有下面的代码。当我使用 echo get_num_queries()时,此页面显示100个查询。我试图减少查询的数量,但我无法找到它们都来自哪里。Wordpress查询和Get_Post_Meta

我唯一能想到的就是get_post_meta。每次都有get_post_meta运行查询吗?如果是的话还有更好的方法来做到这一点,所以我不会每次运行一个查询?

<?php 
/* This is the second wordpress loop which will show only non paid dealers per the above wp_query in query_single. The 0 passed is non-paid dealers*/ 

    query_single('dealers', 'draft', '0', $taxtype, $value); 
?> 

<?php if (have_posts()) : ?> 
<?php while (have_posts()) : the_post(); ?> 

<?php 
$address=get_post_meta($post->ID, 'wpcf-street_address', TRUE); 
$city=get_post_meta($post->ID, 'wpcf-city', TRUE); 
$state=get_post_meta($post->ID, 'wpcf-state_abbreviation', TRUE); 
$zip=get_post_meta($post->ID, 'wpcf-zip_code', TRUE); 
$phone=get_post_meta($post->ID, 'wpcf-phone_number', TRUE); 
$paid=get_post_meta($post->ID, 'wpcf-paid', TRUE); 
$post_id=get_the_ID(); 
get_each_dealer_brand($post_id);?> 

<ul class="ullisting"> 
<?php 
if($paid==0) { 

    echo "<li><p class=\"plisting\"><strong>";the_title();echo "</strong></p></li>"; 
    echo "<li><p class=\"plisting\">$address | $city, $state $zip</p></li>"; 
    echo "<li><p class=\"plisting\">P: $phone</p></li>"; 
    echo "<li><p class=\"listing\"><span><small>$brands_list</small></span></p></li>"; 
} 
?> 
</ul> 

回答

0

你可以通过调用get_post_meta一次减少你的查询次数 - 这将抓住所有的相关领域:

// will have all of your fields and more in an array, with fewer queries called 
$post_meta = get_post_meta($post->ID); 
var_dump($post_meta); 

http://codex.wordpress.org/Function_Reference/get_post_meta

+0

谢谢你这么多的建议。 – user1609391 2013-02-23 08:29:00