Title: creating a widget
Last modified: August 24, 2016

---

# creating a widget

 *  [pahroblem](https://wordpress.org/support/users/pahroblem/)
 * (@pahroblem)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/creating-a-widget-2/)
 * hey guys been trying this for awhile now, finally got my review section of my
   site running and want to create a widget that lists 8 random reviews in my sidebar.
 * I’ve tried a few tutorials on making a widget but i cant get it to work with 
   my query for the reviews.
 * heres the code for the review list
 *     ```
       <div class="review-list">
   
       <h2 class="review-titleblock">Reviews</h2>
   
       <div class="score">
   
       <?php $args = array(
       	'post_type' => 'reviews',
       	'orderby'   => 'rand',
       	'meta_key'  => 'mymetabox_Score',
       	'posts_per_page' => 8,
   
       );
       $query = new WP_Query( $args ); ?>
   
       <?php if ( $query->have_posts() ) : ?>
       <?php while ( $query->have_posts() ) : $query->the_post(); ?>
   
       <div id="review-item"><div class="post-<?php the_ID(); ?>" <?php post_class(); ?>>
   
       			<a href="<?php echo the_permalink(); ?>">
                                       <h4 class="review-list-title"><?php the_title(); ?></h4>
   
       			</a>
             <div class="review-scorebg"><?php gamergreed_score(); ?></div>
       </div>
   
       		<?php endwhile; ?>
   
       <?php wp_reset_postdata(); ?>
       <?php else : ?>
       <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
       <?php endif; ?>
   
       </div>
   
       </div>
       </div>
       ```
   
 * can anyone help me add this into a widget i can add into my sidebar?
 * thanks in advance!

Viewing 1 replies (of 1 total)

 *  [John Parris](https://wordpress.org/support/users/mindctrl/)
 * (@mindctrl)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/creating-a-widget-2/#post-6148328)
 * Try this plugin: [https://wordpress.org/plugins/php-code-widget/](https://wordpress.org/plugins/php-code-widget/)

Viewing 1 replies (of 1 total)

The topic ‘creating a widget’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [John Parris](https://wordpress.org/support/users/mindctrl/)
 * Last activity: [10 years, 12 months ago](https://wordpress.org/support/topic/creating-a-widget-2/#post-6148328)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
