I’ve got a WordPress theme options page with some text values for the user to input. This works fine.
What I’m struggling with is this final step of getting the user to select a page to use as a link in the website header.
I’ve got as far as making the drop down list of pages appear, but Im not sure how to get this to save permenantly, and how to get the value out.
Here is the relevent part of my Functions.php file:
/**
* Global fields
*/
//Custom Theme Settings
add_action('admin_menu', 'add_gcf_interface');
function add_gcf_interface() {
add_options_page('Quick access bar', 'Quick access bar', '8', 'functions', 'editglobalcustomfields');
}
function editglobalcustomfields() {
?>
<div class='wrap'>
<h2>Quick access bar fields</h2>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options') ?>
<p><strong>Phone number:</strong><br />
<input type="text" name="phonenum" size="45" value="<?php echo get_option('phonenum'); ?>" /></p>
<p><strong>Email address:</strong><br />
<input type="text" name="emailaddress" size="45" value="<?php echo get_option('emailaddress'); ?>" /></p>
<p><strong>Choose page link 1:</strong><br />
<?php wp_dropdown_pages( array(
'name' => 'qab_link1[whatever_page]',
'show_option_none' => __( 'â Select â' ),
'option_none_value' => '0',
'selected' => $options['whatever_page']
)); ?>
<p><input type="submit" name="Submit" value="Save and publish" /></p>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="phonenum,emailaddress" />
</form>
</div>
<?php
}
The
name
parameter is what you’ll use to get it’s value with theget_option
function. Try altering your code toIn the name you’ll use
whatever_page
, so you can catch the value of it withget_option('whatever_page')
. Use that inselected
parameter to retrieve the actual value and make it’s<option>
selected.