Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: implode() [function.implode]: Invalid arguments passed

Tags:

I'm getting the error below...

Warning: implode() [function.implode]: Invalid arguments passed in \wp-content/themes/mytheme/functions.php on line 1335

at...

function my_get_tags_sitemap(){     if ( !function_exists('wp_tag_cloud') || get_option('cb2_noposttags')) return;     $unlinkTags = get_option('cb2_unlinkTags');      echo '<div class="tags"><h2>Tags</h2>';     if($unlinkTags)     {         $tags = get_tags();         foreach ($tags as $tag){             $ret[]= $tag->name;         }         //ERROR OCCURS HERE         echo implode(', ', $ret);     }     else     {         wp_tag_cloud('separator=, &smallest=11&largest=11');     }     echo '</div>'; } 

Any ideas how to intercept the error. The site has exactly one tag.

like image 444
Scott B Avatar asked Mar 12 '11 01:03

Scott B


2 Answers

You are getting the error because $ret is not an array.

To get rid of the error, at the start of your function, define it with this line: $ret = array();

It appears that the get_tags() call is returning nothing, so the foreach is not run, which means that $ret isn't defined.

like image 60
Mark Eirich Avatar answered Sep 25 '22 13:09

Mark Eirich


You can try

echo implode(', ', (array)$ret); 
like image 22
蔡正海 Avatar answered Sep 25 '22 13:09

蔡正海