Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress WordPress Settings API Creating Multiple Setting Fields Input Setting Field Example

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 90,845 Points

Saving 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
Jonathan Grieve
Treehouse Moderator 90,845 Points

I've partially resolved this by removing the isset check from the code.

<?php
function wpt_slideshow_input_callback() {

    $options = get_option( 'wpt_input_test' );  

    echo '<input type="text" id="wpt_input_test" name="wpt_input_test" value="' . $options . '" placeholder="Example field theme setting">';
}
?>

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.