我需要计算整个网站上使用“产品标签”的次数。每个产品都有许多与之相关的标签。
我考虑过创建一个短代码,然后在需要时可以引用。我在下面创建的短代码会使网站崩溃。
// function
function tag_count_shortcode() {
// Identify the tag ID and then run a count.
$term = get_tag( $tag_ID );
$count = $term->count;
// Output the total number of times a tag is used
return $count;
}
// register shortcode
add_shortcode('tagcount', 'tag_count_shortcode');
我不确定我哪里出了问题。非常感谢任何帮助。
平台:WordPress | 包含代码的文件:“Functions.php”
largeQ