'widget_recent_reviews', 'description' => __( "The most recent reviews on your site") ); parent::__construct('recent-reviews', __('Recent Reviews'), $widget_ops); $this->alt_option_name = 'widget_recent_reviews'; add_action( 'save_post', array(&$this, 'flush_widget_cache') ); add_action( 'deleted_post', array(&$this, 'flush_widget_cache') ); add_action( 'switch_theme', array(&$this, 'flush_widget_cache') ); } function widget($args, $instance) { $cache = wp_cache_get('widget_recent_reviews', 'widget'); //$rating_name = 'Set Product Name'; // define if ( !is_array($cache) ) $cache = array(); if ( isset($cache[$args['widget_id']]) ) { echo $cache[$args['widget_id']]; return; } ob_start(); extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Reviews') : $instance['title'], $instance, $this->id_base); if ( ! $number = absint( $instance['number'] ) ) $number = 10; $r = new WP_Query(array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'meta_key'=>'ta_post_review_rating', 'ignore_sticky_posts' => true)); if ($r->have_posts()) : ?> flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( isset($alloptions['widget_recent_entries']) ) delete_option('widget_recent_entries'); return $instance; } function flush_widget_cache() { wp_cache_delete('widget_recent_reviews', 'widget'); } function form( $instance ) { $title = isset($instance['title']) ? esc_attr($instance['title']) : ''; $number = isset($instance['number']) ? absint($instance['number']) : 5; ?>