I'm trying to display the post tags through a widget, I've following codes and getting error "Undefined variable: array":
if ( $instance['stats_tag']['category'] ) {
$posttags = get_the_tags();
if ($posttags) {
$array = array();
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$array[] = '<a href="' . esc_url( $link ) . '" rel="tag" itemprop="keywords">' . $tag->name . '</a>';
}
}
if ( $stats != '' ) {
$stats[] = '<span class="the-day-tags">' . implode(', ', (array)$array). '</span>' ;
}
Can anyone help me to fix the issue ?