1

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

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

1 Answer 1

1

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']
        )
    );
} ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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