• Hello,

    I’m really hoping that someone can help me out here, I’m trying to give the admin the ability to choose a page for a button to link to. I’ve created the select using
    wp_dropdown_pages($args)
    and am creating the arguments via

    $args = array(
    'echo'  => 1,
    'selected' => $the_link,
    'name'  => 'theme_option[the_link]');

    and have attempted to save the value generated
    $input['the_link'] = (int) $input['the_link'];
    … but so far no luck. The selected option just resets once the form has been sent, and it doesn’t look like the value is getting saved at all. Does anyone have any advice?

Viewing 15 replies - 16 through 30 (of 30 total)
  • Thread Starter ColoursB

    (@coloursb)

    You got it!

    <select name='the_link' id='the_link'>
    
    <option class="level-0" value="207">Animals</option>
    
    <option class="level-0" value="13">Blog</option>
    
    <option class="level-0" value="10">Contact Page</option>
    
    <option class="level-0" value="12">Features</option>
    
    <option class="level-1" value="93">&nbsp;&nbsp;&nbsp;Accordion</option>
    
    <option class="level-1" value="16">&nbsp;&nbsp;&nbsp;Buttons</option>
    
    <option class="level-1" value="14">&nbsp;&nbsp;&nbsp;Columns</option>
    
    <option class="level-1" value="22">&nbsp;&nbsp;&nbsp;Image Gallery</option>
    
    <option class="level-1" value="20">&nbsp;&nbsp;&nbsp;Tables</option>
    
    <option class="level-1" value="174">&nbsp;&nbsp;&nbsp;Tabs</option>
    
    <option class="level-0" value="6">Home</option>
    
    <option class="level-0" value="58">Pages</option>
    
    <option class="level-1" value="59">&nbsp;&nbsp;&nbsp;Staff</option>
    
    <option class="level-1" value="168">&nbsp;&nbsp;&nbsp;Testimonials</option>
    
    <option class="level-0" value="2">Sample Page</option>
    
    </select>

    So it looks like the values are being created, but for some reason they aren’t being saved.

    Timothy Jacobs

    (@timothyblynjacobs)

    how were you able to see what the link was? you said it was saying “”. How did you get it to display that?

    Thread Starter ColoursB

    (@coloursb)

    On the homepage where I’ve added `$options = get_option(‘theme_options’);
    “>Button‘. So when I re-save the theme-options.php (where the select is being generated) and refresh the homepage, I can see the link’s href=”0″ in the browser.

    Timothy Jacobs

    (@timothyblynjacobs)

    Ok, does the select reset on every page load?

    Thread Starter ColoursB

    (@coloursb)

    Yes

    Timothy Jacobs

    (@timothyblynjacobs)

    Because I’m running out of ideas try changing 'name' => 'the_link' to
    'name' => 'critter_theme_options[the_link]'

    Thread Starter ColoursB

    (@coloursb)

    Woot! Ok now the link’s href= the correct value, now how do I snatch the select’s # value and display the actual page’s link?

    Timothy Jacobs

    (@timothyblynjacobs)

    you want the link to the post correct?

    Thread Starter ColoursB

    (@coloursb)

    Haha preferably

    Thread Starter ColoursB

    (@coloursb)

    Well, the page in this case

    Timothy Jacobs

    (@timothyblynjacobs)

    Assuming you’ve got the ID in a variable called $id
    $link = get_permalink( $id );

    Thread Starter ColoursB

    (@coloursb)

    Where should I put this?

    Timothy Jacobs

    (@timothyblynjacobs)

    Where ever you want to put the link so for example.

    $options = get_option( 'critter_theme_options' );
    $id = $options['the_link'];
    $link = get_permalink( $id );
    
    <a href="<?php echo $link; ?>">Whatever you want linked text to be</a>
    Thread Starter ColoursB

    (@coloursb)

    You are AMAZING!
    Thank you so much, I owe you big time!!!!!!

    Timothy Jacobs

    (@timothyblynjacobs)

    No problem! It only took about 30 posts back and forth lol.

Viewing 15 replies - 16 through 30 (of 30 total)
  • The topic ‘Trouble saving wp_dropdown_pages value’ is closed to new replies.