David Garcia
David Garcia

Reputation: 2696

Wordpress: Limit number of tags added to post

in this code;

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

How can i limit the number of tags added to the post?

Will this work

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;
}

Upvotes: 0

Views: 768

Answers (1)

David Garcia
David Garcia

Reputation: 2696

Yes it worked!!!!!

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;
}

Upvotes: 1

Related Questions