In the script below, I’m getting an invalid arguments error on the “echo implode()” line:
Warning: implode() [function.implode]:
Invalid arguments passed in…
Here is the script:
if ( !function_exists('wp_tag_cloud') || get_option('cb2_noposttags')) return;
$unlinkTags = get_option('cb2_unlinkTags');
echo '<div class="links"><h2>Tags</h2>';
if($unlinkTags)
{
$tags = get_tags();
foreach ($tags as $tag){
$ret[]= $tag->name;
}
echo implode(', ', $ret);
}
else
{
wp_tag_cloud('separator=, &smallest=11&largest=11');
}
echo '</div>';
How might I rework this to catch the invalid argument?
Initialise $ret as an array before your foreach loop.
Then, if get_tags() doesn’t return anything, $ret is still being passed into implode as an array (but as an empty array) rather than as a null