Some more context of where this is in your php file would be helpful. Are you saving that value to the database anywhere with a function like update_option() or update_user_meta(). If not, wordpress has no way of storing that information. What you seem to be doing is adding the value from the select into a variable, but not actually storing that variable anywhere. Does that make sense?
So it’s not likely that the info is getting stored in the database? Could you explain how to use update_option() in this case to save the value?
Take a look at the codex page first, and if you have any questions just come back here, and I’ll be glad to help. Basically you are going to retrieve the option from the database like
$options = get_option('your_option_name');
and then display it where ever you want with
echo $options
to save to the database will get more complicated depending on where it is being done, which is why I need the context.
Sorry, I’m still a bit confused. So I’ve used the code mentioned in my first post within my theme-options.php page to let the admin select an existing page for a button on the homepage to link to. In the part of the document that saves all of the other values, I’ve used
$input['the_link'] = get_option('the_link');
return $input;
to try and save it. On the actual homepage where the button is, I’ve used
$options = get_option('theme_options');
<a href="<?php echo $options['the_link'];?>">Button</a>
to display the selected page. Does that make sense?
I need more context on where this selection is.
Here is the whole theme-options.php
[Moderated – That’s too much code to post here – please use a pastebin – http://codex.wordpress.org/Forum_Welcome#Posting_Code ]
Pastebin
This is different because you are integrating into the theme options which is using the options api.
Where in this massive file are your changes.
Sorry, here is the pastebin link http://pastebin.com/7TvvS2gP
I’m trying to implement the link from the Doctors/Staff CTA button link (check out line 158). I really appreciate you taking the time to look at this, thank you so much!
Ok so change this wp_dropdown_pages($arg); to this
$arg = array(
'name' => 'the_link',
'selected' => $options['the_link'],
);
wp_dropdown_pages($arg);
and then use the original save function you had
$input['the_link'] = (int) $input['the_link'];
No problem!
I hate to keep bothering you, sorry! When I copy
input['the_link'] = (int) $input['the_link']' just after $input['the_link'] = get_option('the_link');, it’s setting the link to ‘/0’. If I toss (int) there is no link at all. 🙁
I apologize, you can probably tell this is my first WordPress theme!
No worries 🙂
Get rid of this $input['the_link'] = get_option('the_link'); We don’t need it. I did’t realize you were already in an options page.
And make sure you have a $ on the first one!
First one what? Same result without the $input['the_link'] = get_option('the_link');
input['the_link'] = (int) $input['the_link']' this should read $input['the_link'] = (int) $input['the_link']
Can you inspect the element using your browser’s dev tools, and copy in the code with the selects?