• 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)
  • 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>';
    }

    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.