foreach is closing after first value then displaying the rem

I wrote a wordpress widget that lists the categories of the blog in a tag. Initially the code I wrote works and you can select a value and when you click save the widget displays the correct information on the front end. However after you hit save when the array is reloaded it looks like this: Elite Featured Junior Varsity …

via PHP Website Development » Search Results » ajax:

foreach is closing after first value then displaying the rem

I wrote a wordpress widget that lists the categories of the blog in a tag. Initially the code I wrote works and you can select a value and when you click save the widget displays the correct information on the front end. However after you hit save when the array is reloaded it looks like this:

I’m not sure how this is happening as the dropdown loads correctly the first time and it is only upon the save and AJAX reload in wordpress that it fails. Here is the code for the widget:
define (‘CHEER_PLUGIN_DIR’, dirname( plugin_basename( __FILE__ ) ));
define (‘CHEER_PLUGIN_URL’, plugins_url() . ‘/’ . CHEER_PLUGIN_DIR);

class cheer_recent_posts extends WP_Widget

/** constructor */
function cheer_recent_posts()
parent::WP_Widget(false, $name = ‘Cheer Samples’);

/** @see WP_Widget::widget */
function widget($args, $instance)
extract( $args );
global $posttypes;

global $cats;
$title = apply_filters(‘widget_title’, $instance[‘title’]);
$cat = $instance[‘cat’];
$number = apply_filters(‘widget_title’, $instance[‘number’]);
$offset = apply_filters(‘widget_title’, $instance[‘offset’]);
$thumbnail_size = apply_filters(‘widget_title’, $instance[‘thumbnail_size’]);
$thumbnail = $instance[‘thumbnail’];
$posttype = $instance[‘posttype’];
?>

echo $before_title . $title . $after_title; ?>
global $post;
$tmp_post = $post;

// get the category IDs and place them in an array

$args = ‘numberposts=’ . $number . ‘&offset=’ . $offset . ‘&post_type=’ . $posttype . ‘&cat=’ . $cat;
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>

Leave a Comment