Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJonathan Grieve
Treehouse Moderator 91,253 PointsSaving the value of an input field with wpt_slideshow_input_callback() callback function.
Hi,
I've been struggling with this over the weekend. My hunch is that since this video was recorded, WordPress has changed the way input text fields are updated. I can get neither the method recorded in the video or the provided code to work.
This is how Zac got the input box to save.
<?php
function wpt_slideshow_input_callback() {
$options = get_option( 'wpt_input_test' );
if( !isset( $options['input_test'] ) ) $options['input_test'] = '';
//echo '<input type="text" id="wpt_input_test" name="wpt_settings[input_test]" value="' . $options['wpt_input_test'] . '" placeholder="Example field theme setting">';
echo '<input type="text" id="wpt_input_test" name="wpt_input_test" value="' . $options . '" placeholder="Example field theme setting">';
}
?>
And this is how it's done in the project downloads.
<?php
function wpt_slideshow_input_callback() {
$options = get_option( 'wpt_input_test' );
if( !isset( $options['input_test'] ) ) $options['input_test'] = '';
echo '<input type="text" id="wpt_input_test" name="wpt_settings[input_test]" value="' . $options['wpt_input_test'] . '" placeholder="Example field theme setting">';
} ?>
Anybody any ideas I'm really stumped with this one.
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsI've partially resolved this by removing the isset check from the code.
I like how it saves even if I log out from the dashboard. One thing it doesn't do is keep the 'settings-updated=true' part of the URL but from what I can tell it is doing what Zac set out to do in the video and that is to save the value in the input field.