I have a plugin I'm developing. As part of its functionality I need to set up an option group and specify an option var for that group:
function swcs_settings() {
register_setting( 'swcs-settings-group', 'swcs_postpage_id' );
}
add_action( 'admin_init', 'swcs_settings' );
Where swcs_postpage_id
is the name of my variable.
I am using this variable in a <select>
box like so:
<select name="swcs_postpage_id" id="swcs_postpage_id" multiple>
<?php global $post;
$args = array( 'numberposts' => -1);
$posts = get_pages($args);
foreach( $posts as $post ) : setup_postdata($post); ?>
<option value="<? echo $post->ID; ?>"><?php the_title(); ?></option>
<?php endforeach; ?>
</select>
As you can see I am using the <select>
with the multiple attribute so a user can make more than one selection if they so desire.
What I'm struggling with is passing more than one value to swcs_postpage_id
. I am guessing that the var really needs to be an array and not a var at all but I am not sure what to do in order to:
- Store multiple values in the option
swcs_postpage_id
- Output and iterate through them using
get_option('swcs_postpage_id');
Any help gratefully received.