Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm building a themes options page using settings API. Everything is ok, but i now i want to create a drop down list populated with pages and i don't know how to!

For example, i have this piece of code that show the list of pages, but when i select a page and cick on save, the page selected doesn't get saved!

    function  combo_select_page_callback() {
$options = get_option('journal_theme_blog_2_col');
    echo "<select name='select_page'>
 <option value=''>";
echo esc_attr( __( 'Select page' ) ); ?></option>
 <?php
  $pages = get_pages();
  foreach ( $pages as $page ) {
    $selected = '<option value="' . get_page_link( $page->ID ) . '">';
    $selected .= $page->post_title;
    $selected .= '</option>';
    echo $selected;
  }
echo '</select>';
}// end combo_select_page_callback

Thank for the help, nelson

share|improve this question
1  
Add the code you use to save the data. –  toscho Jul 19 '12 at 10:47
    
I think i have found the solution: –  naires Jul 19 '12 at 11:06
    
@naires Then add it as answer, wait for two days and mark it as solution. –  kaiser Jul 27 '12 at 2:02
    
You are right kaiser. i just did. thank you for the attention. –  naires Jul 27 '12 at 8:54

1 Answer 1

up vote 1 down vote accepted

I have found the solution. I used the wordpress function wp_dropdown_pages

<?php function  combo_select_page_callback() {
$options = get_option('function plugin');
    wp_dropdown_pages(
        array(
             'name' => 'function plugin[ID used to identify the field throughout the theme]',
             'echo' => 1,
             'show_option_none' => __( '&mdash; Select &mdash;' ),
             'option_none_value' => '0',
             'selected' => $options['ID used to identify the field throughout the theme']
        )
    );
} ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.