我的一个页面上有以下代码。我使用时,此页面显示100个查询
echo get_num_queries()
。我正在尝试减少查询量,但我无法找到它们的来源。
我唯一能想到的就是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 :(得分: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);