WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] settings API dropdown list to select page (3 posts)

  1. accounts@push
    Member
    Posted 2 years ago #

    hi there i'm attempting to difine a function that will display a dropdown list of the pages on my wordpress site - currently my functions.php file resembles closely to otto's wordpress settings API tutorial found here.

    currently i am using the following function to display a dropdown list and am able to get it to populate the <select> tag with my pages however when i chose the page and submit it the option does not save to my database.

    function  setting_dropdown_fn() {
    	$options = get_option('rtms_options');
    
    	$args = array(
        'depth'            => 0,
        'child_of'         => 0,
        'selected'         => 0,
        'echo'             => 1,
        'name'             => "rtms_options[Page_string]",
    	'id'			   => "dropdown")
    	;
    	wp_dropdown_pages( $args );
    
    	}

    any advice on where i'm going wrong or where i need to be looking into would be very helpful - as i said before i'm trying to now save the populated list selection to my database

  2. accounts@push
    Member
    Posted 2 years ago #

    the following code will do the same in terms of populating the list however it will not save either.

    function  setting_dropdown_fn() {
    	$options = get_option('rtms_options');
    	echo "<select name='page-dropdown'>
     <option value=''>";
    echo esc_attr( __( 'Select page' ) ); ?></option>
     <?php
      $pages = get_pages();
      foreach ( $pages as $pagg ) {
      	$option = '<option value="' . get_page_link( $pagg->ID ) . '">';
    	$option .= $pagg->post_title;
    	$option .= '</option>';
    	echo $option;
      }
    echo '</select>';}
  3. alvaro05
    Member
    Posted 1 year ago #

    Did you end up with a solution?

Topic Closed

This topic has been closed to new replies.

About this Topic