How to save get_pages custom meta field select value
-
Hello,
I have created a custom meta field that displays a list of the published pages in a select field.
I am struggling to save and display the values when the page has been saved.
The code using to generate the select options
$item_section_two_link = get_post_meta ($post->ID, 'item_section_two_link_field', true ); $posts = get_pages(array('post_type'=> 'page', 'post_status'=> 'publish', 'suppress_filters' => false, 'posts_per_page'=>-1)); echo '<select name="item_section_two_link_field" id="'.$select_id.'">'; echo '<option value = "test" >All '.$label.' </option>'; foreach ($posts as $post) { echo '<option value="', $item_section_two_link, '"', $selected == $post->ID ? ' selected="selected"' : '', '>', $post->post_title, '</option>'; } echo '</select>'; ?>
I use save_post to save tehother meta boxes (text, textarea etc) but can’t save the select field – code below
if ( ! isset( $_POST['item_section_two_link'] ) ) { return; } $item_featured_link_save = ( $_POST['item_section_two_link'] ); update_post_meta( $post_id, 'item_section_two_link_field', $item_featured_link_save );
Any help much appreciated
Thanks
- The topic ‘How to save get_pages custom meta field select value’ is closed to new replies.