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

前端 未结 4 1498
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 19:23

I\'m getting the error below...

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

at...

相关标签:
4条回答
  • 2021-02-01 19:50

    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.

    0 讨论(0)
  • 2021-02-01 20:04
    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>';
        $ret = []; // here you need to add array which you call inside implode function
        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>';
    }
    
    0 讨论(0)
  • 2021-02-01 20:14

    You can try

    echo implode(', ', (array)$ret);
    
    0 讨论(0)
  • 2021-02-01 20:14

    It happens when $ret hasn't been defined. The solution is simple. Right above $tags = get_tags();, add the following line:

    $ret = array();
    
    0 讨论(0)
提交回复
热议问题