您好,没有更好的选择,但为了加快速度,您可以使用wordpress transient,请参阅文档:http://codex.wordpress.org/Transients_API
您的代码如下所示(我对其进行了位清理,并使用函数empty检查数组…):
<?php
if ( false === ( $tag_descrip = get_transient( \'tag_descrip\' ) ) ) {
$tag_descrip = get_terms( \'product_tag\', \'orderby=count&hide_empty=0\' );
set_transient( \'tag_descrip \', $tag_descrip );
}
if ( !empty($tag_descrip) ){
foreach ( $tag_descrip as $tag_descrip ) {
if($tag_descrip->name == "parfum_bestof")
$title_new1 = $tag_descrip->description;
if($tag_descrip->name == "tshirt_bestof")
$title_new2 = $tag_descrip->description;
if($tag_descrip->name == "child_bestof")
$title_new3 = $tag_descrip->description;
}
}
?>