I am working on a custom plugin. Now I have a dropdown to select and store settings to the database. When I select a post in the dropdown and click on save, the selection is stored and working but the drop down selection falls back to the first entry.
Can you help me how to make this work that it shows what is really stored in the database?
Here is the screenshot of the admin page and also the code:
$event_id = get_post_meta($post->ID, 'nwswa_event_mailtpl', true);
echo '<p><label for="event_mailtpl">Mailvorlage:</label>';
echo '<select id="event_mailtpl" name="event_mailtpl">';
// Query the events here
$query = new WP_Query( 'post_type=nwswa_mailtpl' );
while ( $query->have_posts() ) {
$query->the_post();
$id = get_the_ID();
$selected = "";
if($id == $event_id){
$selected = ' selected="selected"';
}
echo '<option' . $selected . ' value=' . $id . '>' . get_the_title() . '</option>';
}
echo '</select></p>';
Best wishes Lukas
