Wordpress:限制添加到帖子的标签数量

时间:2012-08-01 08:42:31

标签: wordpress

在此代码中;

if (!is_array($keywords)) {
$keywords = explode(',', $keywords);
}
foreach ($keywords as $thetag) {
wp_add_post_tags($post_id, $thetag);
}

如何限制添加到帖子中的标签数量?

这会有效吗

if (!is_array($keywords)) {
$count=0;
$keywords = explode(',', $keywords);
}
foreach ($keywords as $thetag) {
$count++;
wp_add_post_tags($post_id, $thetag);
if( $count > 3 ) break;
}

1 个答案:

答案 0 :(得分:1)

是的,它有效!!!!!

if (!is_array($keywords)) {
$count=0;
$keywords = explode(',', $keywords);
}
foreach ($keywords as $thetag) {
$count++;
wp_add_post_tags($post_id, $thetag);
if( $count > 3 ) break;
}