1

I'm currently developing a games database for my wordpress site and one of the custom functions is entering a review score for a game, we have a 1-10 based rating system but I wish to add another option to this loop "No Review", how can I do this?

<select style="width: 100px" name="games_database_rating">
  <?php // Generate all items of drop-down list
  for ( $rating = 10; $rating >= 1; $rating -- ) {
  ?>
  <option value="<?php echo $rating; ?>" <?php echo selected( $rating, $game_rating ); ?>>
  <?php echo $rating; ?>/10 <?php } ?>
</select>

1 Answer 1

2

You just need to add a static <option> element before you start your loop.

<select style="width: 100px" name="games_database_rating">
  <option value="none">No Rating</option>
  <?php // Generate all items of drop-down list
      for ( $rating = 10; $rating >= 1; $rating -- ) {
  ?>
     <option value="<?php echo $rating; ?>" <?php echo selected( $rating, $game_rating ); ?>>
     <?php echo $rating; ?>/10 <?php } ?>
</select>

Now your select will start out with "No Rating", and you can still choose a number. When you submit the form, just check for "none" or the number.

2
  • Ahh but if No Review is selected then the database wont remember the selection in the dashboard because it's outside of the loop?
    – Dave Burns
    Commented Aug 9, 2013 at 16:36
  • Actually ignore that, it seems to be working perfectly :)
    – Dave Burns
    Commented Aug 9, 2013 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.