Skip to main content
added 75 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

In the core, the bottom input names are marked with the instance number, e.g. new_role (top) and new_role2 (bottom). Here are two approaches to usefor a similar naming convensionconvention, namely course_section1 (top) and course_section2 (bottom):

function add_course_section_filter() 
{
    static $count =$instance= 0;    

    // Dropdown options         
    $options = '';
    foreach( range( 1, 3 ) as $rng )
    {
        $options = sprintf( 
            '<option value="%1$d" %2$s>Section %1$d</option>',
            $rng,
            selected( $rng, get_selected_course_section(), 0 )
        );
    }

    // Display dropdown with a different name for each instance
    printf( 
        '<select name="%s" style="float:none;"><option value="0">%s</option>%s</select>', 
        'course_section' . ++$count++$instance,
        __( 'Course Section...' ),
        $options 
    );


    // Button
    printf (
        '<input id="post-query-submit" type="submit" class="button" value="%s" name="">',
        __( 'Filter' )
    );
}
add_action( 'restrict_manage_users', 'add_course_section_filter' );

where we used the core function selected()selected() and the helper function:

In the core, the bottom input names are marked with the instance number, e.g. new_role (top) and new_role2 (bottom). Here are two approaches to use a similar naming convension, namely course_section1 (top) and course_section2 (bottom):

function add_course_section_filter() 
{
    static $count = 0;  

    // Dropdown options         
    $options = '';
    foreach( range( 1, 3 ) as $rng )
    {
        $options = sprintf( 
            '<option value="%1$d" %2$s>Section %1$d</option>',
            $rng,
            selected( $rng, get_selected_course_section(), 0 )
        );
    }

    // Display dropdown with a different name for each instance
    printf( 
        '<select name="%s" style="float:none;"><option value="0">%s</option>%s</select>', 
        'course_section' . ++$count,
        __( 'Course Section...' ),
        $options 
    );


    // Button
    printf (
        '<input id="post-query-submit" type="submit" class="button" value="%s" name="">',
        __( 'Filter' )
    );
}
add_action( 'restrict_manage_users', 'add_course_section_filter' );

where we used the core function selected() and the helper function:

In the core, the bottom input names are marked with the instance number, e.g. new_role (top) and new_role2 (bottom). Here are two approaches for a similar naming convention, namely course_section1 (top) and course_section2 (bottom):

function add_course_section_filter() 
{
    static $instance= 0;    

    // Dropdown options         
    $options = '';
    foreach( range( 1, 3 ) as $rng )
    {
        $options = sprintf( 
            '<option value="%1$d" %2$s>Section %1$d</option>',
            $rng,
            selected( $rng, get_selected_course_section(), 0 )
        );
    }

    // Display dropdown with a different name for each instance
    printf( 
        '<select name="%s" style="float:none;"><option value="0">%s</option>%s</select>', 
        'course_section' . ++$instance,
        __( 'Course Section...' ),
        $options 
    );


    // Button
    printf (
        '<input id="post-query-submit" type="submit" class="button" value="%s" name="">',
        __( 'Filter' )
    );
}
add_action( 'restrict_manage_users', 'add_course_section_filter' );

where we used the core function selected() and the helper function:

added 40 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

Let's hook into restrict_manage_users, to create twodisplay dropdowns, with a different namesname for each instance:

Let's hook into restrict_manage_users, to create two dropdowns with different names:

Let's hook into restrict_manage_users, to display dropdowns, with a different name for each instance:

added 40 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251
function add_course_section_filter() 
{
    static $count = 0;  

    printf(// Dropdown options         
    $options = '';
  '<select name="%s" style="float:none;"><optionforeach( value="0">%s</option>'range( 1, 3 ) as $rng )
    {
    'course_section' . ++$count,  $options = sprintf( 
        __( 'Course Section...' ) '<option value="%1$d" %2$s>Section %1$d</option>',
    );
        $rng,
    foreach( range       selected( 1$rng, 3get_selected_course_section(), 0 ) 
 as $rng      );
    {}

    // Display dropdown with printf(a different name for each instance
    printf(  
       '<option value="%1$d"'<select %2$s>Sectionname="%s" %1$d<style="float:none;"><option value="0">%s</option>'option>%s</select>',
   
        'course_section' . $rng++$count,
        __( 'Course Section...' ),
 selected( $rng, get_selected_course_section(), 0 )
   $options  
    ); 


    }
// Button
    printf (
        '<input id="post-query-submit" type="submit" class="button" value="%s" name="">',
        __( 'Filter' )
    );
}
add_action( 'restrict_manage_users', 'add_course_section_filter' );
function add_course_section_filter() 
{
    static $count = 0;  

    printf( 
        '<select name="%s" style="float:none;"><option value="0">%s</option>', 
        'course_section' . ++$count,
        __( 'Course Section...' ) 
    );
        
    foreach( range( 1, 3 ) as $rng )
    {
        printf( 
            '<option value="%1$d" %2$s>Section %1$d</option>',
            $rng,
            selected( $rng, get_selected_course_section(), 0 )
        );
    }

    printf (
        '<input id="post-query-submit" type="submit" class="button" value="%s" name="">',
        __( 'Filter' )
    );
}
add_action( 'restrict_manage_users', 'add_course_section_filter' );
function add_course_section_filter() 
{
    static $count = 0;  

    // Dropdown options         
    $options = '';
    foreach( range( 1, 3 ) as $rng )
    {
        $options = sprintf( 
            '<option value="%1$d" %2$s>Section %1$d</option>',
            $rng,
            selected( $rng, get_selected_course_section(), 0 ) 
        );
    }

    // Display dropdown with a different name for each instance
    printf(  
        '<select name="%s" style="float:none;"><option value="0">%s</option>%s</select>',  
        'course_section' . ++$count,
        __( 'Course Section...' ),
        $options  
    ); 


    // Button
    printf (
        '<input id="post-query-submit" type="submit" class="button" value="%s" name="">',
        __( 'Filter' )
    );
}
add_action( 'restrict_manage_users', 'add_course_section_filter' );
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251
Loading