Title: Loop within a Plugin changes read/write title
Last modified: August 20, 2016

---

# Loop within a Plugin changes read/write title

 *  [MatthijsdeGraaf](https://wordpress.org/support/users/matthijsdegraaf/)
 * (@matthijsdegraaf)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/loop-within-a-plugin-changes-readwrite-title/)
 * Hi there,
 * I am building a plugin with which I can select a custom post type-post for a 
   page within the write/edit screen of a page.
 * I do this by creating a <select> component filled the String, which I get through:
 *     ```
       // The Query
       query_posts('post_type=news&order=ASC');
   
       // The Loop
       $String = '<option value="0">-</option>';
       while ( have_posts() ) : the_post();
       	if($mdg_footer == get_the_ID()){
       		$String .= '<option value="'. get_the_ID() .'" selected="yes">' . get_the_title() . '</option>';
       	}else{
       		$String .= '<option value="'. get_the_ID() .'">' . get_the_title() . '</option>';
       	}
       endwhile;
   
       // Reset Query
       wp_reset_query();
       ```
   
 * However, each time when I open the page the title of the page changes to the 
   last item of the loop.
 * Resetting the loop doesn’t change anything
 * Does anyone know how to prevent the title from being changed?
 * Thanks in Advance

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Marventus](https://wordpress.org/support/users/marventus/)
 * (@marventus)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/loop-within-a-plugin-changes-readwrite-title/#post-2293630)
 * Hi Matt,
 * I don’t know if this could be the source of your problem, but in your if statement
   you seem to be adding to the default value of your `$string` instead of replacing
   it with the updated one.
    Try replacing this:
 *     ```
       if($mdg_footer == get_the_ID()){
          $String .= '<option value="'. get_the_ID() .'" selected="yes">' . get_the_title() . '</option>';
       }else{
          $String .= '<option value="'. get_the_ID() .'">' . get_the_title() . '</option>';
       }
       ```
   
 * with this:
 *     ```
       if($mdg_footer == get_the_ID()){
          $String = '<option value="'. get_the_ID() .'" selected="yes">' . get_the_title() . '</option>';
       }else{
          $String = '<option value="'. get_the_ID() .'">' . get_the_title() . '</option>';
       }
       ```
   
 *  [Marventus](https://wordpress.org/support/users/marventus/)
 * (@marventus)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/loop-within-a-plugin-changes-readwrite-title/#post-2293753)
 * Hi Matt,
 * Did you solve your issue? If so, could you please mark your topic as resolved?
 * Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Loop within a Plugin changes read/write title’ is closed to new replies.

## Tags

 * [changed](https://wordpress.org/support/topic-tag/changed/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [title](https://wordpress.org/support/topic-tag/title/)

 * 2 replies
 * 2 participants
 * Last reply from: [Marventus](https://wordpress.org/support/users/marventus/)
 * Last activity: [14 years, 7 months ago](https://wordpress.org/support/topic/loop-within-a-plugin-changes-readwrite-title/#post-2293753)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
