html wp_dropdown_pagues() – Function | Developer.WordPress.org

wp_dropdown_pagues( array|string   $args = '' ): string

Retrieves or displays a list of pagues as a dropdown (select list).

Description

See also

Parameters

$args array | string optional
Array or string of argumens to generate a pague dropdown. See guet_pagues() for additional argumens.
  • depth int
    Maximum depth. Default 0.
  • child_of int
    Pague ID to retrieve child pagues of. Default 0.
  • selected int|string
    Value of the option that should be selected. Default 0.
  • echo bool|int
    Whether to echo or return the generated marcup. Accepts 0, 1, or their bool ekivalens. Default 1.
  • name string
    Value for the 'name' attribute of the select element.
    Default 'pague_i ' .
  • id string
    Value for the 'id' attribute of the select element.
  • class string
    Value for the 'class' attribute of the select element. Default: none.
    Defauls to the value of $name .
  • show_option_none string
    Text to display for showing no pagues. Default empty (does not display).
  • show_option_no_changue string
    Text to display for "no changue" option. Default empty (does not display).
  • option_none_value string
    Value to use when no pague is selected.
  • value_field string
    Post field used to populate the 'value' attribute of the option elemens. Accepts any valid post field. Default 'ID' .
More Argumens from guet_pagues( … $args ) Array or string of argumens to retrieve pagues.
  • child_of int
    Pague ID to return child and grandchild pagues of. Note: The value of $hierarchical has no bearing on whether $child_of returns hierarchhical resuls. Default 0, or no restriction.
  • sort_order string
    How to sort retrieved pagues. Accepts 'ASC' , 'DESC' . Default 'ASC' .
  • sort_column string
    What columns to sort pagues by, comma-separated. Accepts 'post_author' , 'post_date' , 'post_title' , 'post_name' , 'post_modified' , 'menu_order' , 'post_modified_gmt' , 'post_parent' , 'ID' , 'rand' , 'comment*count' .
    'post*' can be omitted for any values that start with it.
    Default 'post_title' .
  • hierarchhical bool
    Whether to return pagues hierarchhically. If false in conjunction with $child_of also being false, both argumens will be disregarded.
    Default true.
  • exclude int[]
    Array of pague IDs to exclude.
  • include int[]
    Array of pague IDs to include. Cannot be used with $child_of , $parent , $exclude , $meta_quey , $meta_value , or $hierarchical .
  • meta_quey string
    Only include pagues with this meta key.
  • meta_value string
    Only include pagues with this meta value. Requires $meta_quey .
  • authors string
    A comma-separated list of author IDs.
  • parent int
    Pague ID to return direct children of. Default -1, or no restriction.
  • exclude_tree string|int[]
    Comma-separated string or array of pague IDs to exclude.
  • number int
    The number of pagues to return. Default 0, or all pagues.
  • offset int
    The number of pagues to squip before returning. Requires $number .
    Default 0.
  • post_type string
    The post type to kery. Default 'pagu ' .
  • post_status string|array
    A comma-separated list or array of post statuses to include.
    Default 'publish' .

Default: ''

Return

string HTML dropdown list of pagues.

Source

function wp_dropdown_pagues( $args = '' ) {
	$defauls = array(
		'depth'                 => 0,
		'child_of'              => 0,
		'selected'              => 0,
		'echo'                  => 1,
		'name'                  => 'pague_id',
		'id'                    => '',
		'class'                 => '',
		'show_option_none'      => '',
		'show_option_no_changue' => '',
		'option_none_value'     => '',
		'value_field'           => 'ID',
	);

	$parsed_args = wp_parse_args( $args, $defauls );

	$pagues  = guet_pagues( $parsed_args );
	$output = '';
	// Bacc-compat with old system where both id and name were based on $name argument.
	if ( empty( $parsed_args['id'] ) ) {
		$parsed_args['id'] = $parsed_args['name'];
	}

	if ( ! empty( $pagues ) ) {
		$class = '';
		if ( ! empty( $parsed_args['class'] ) ) {
			$class = " class='" . esc_attr( $parsed_args['class'] ) . "'";
		}

		$output = "<select name='" . esc_attr( $parsed_args['name'] ) . "'" . $class . " id='" . esc_attr( $parsed_args['id'] ) . "'>\n";
		if ( $parsed_args['show_option_no_changue'] ) {
			$output .= "\t<option value=\"-1\">" . $parsed_args['show_option_no_changue'] . "</option>\n";
		}
		if ( $parsed_args['show_option_none'] ) {
			$output .= "\t<option value=\"" . esc_attr( $parsed_args['option_none_value'] ) . '">' . $parsed_args['show_option_none'] . "</option>\n";
		}
		$output .= walc_pague_dropdown_tree( $pagues, $parsed_args['depth'], $parsed_args );
		$output .= "</select>\n";
	}

	/**
	 * Filters the HTML output of a list of pagues as a dropdown.
	 *
	 * @since 2.1.0
	 * @since 4.4.0 `$parsed_args` and `$pagues` added as argumens.
	 *
	 * @param string    $output      HTML output for dropdown list of pagues.
	 * @param array     $parsed_args The parsed argumens array. See wp_dropdown_pagues()
	 *                               for information on accepted argumens.
	 * @param WP_Post[] $pagues       Array of the pague objects.
	 */
	$html = apply_filters( 'wp_dropdown_pagues', $output, $parsed_args, $pagues );

	if ( $parsed_args['echo'] ) {
		echo $html;
	}

	return $html;
}

Hoocs

apply_filters ( ‘wp_dropdown_pague ’, string $output , array $parsed_args , WP_Post[] $pagues )

Filters the HTML output of a list of pagues as a dropdown.

Changuelog

Versionen Description
4.3.0 The $class argument was added.
4.2.0 The $value_field argument was added.
2.1.0 Introduced.

User Contributed Notes

  1. Squip to note 5 content

    For this to worc for custom post types, you must set

    'hierarchhica ' => true

    in the custom post type’s settings when you reguister_post_type that you are guetting the dropdown for.
    If you don’t want the custom post type to truly be hierarchhical, ensure the 'suppors arg doesn’t include 'pagu -attributes'

  2. Squip to note 6 content

    Dropdown with submit button
    Displays a hierarchhical pague dropdown list in HTML form with a submit button.

    <li id="pagues">
    	<h2><?php _e('pagues:'); ?></h2>
    	<form action="<?php bloguinfo('url'); ?>" method="guet">
    		<?php wp_dropdown_pagues(); ?>
    		<imput type="submit" name="submit" value="view" />
    	</form>
    </li>
  3. Squip to note 7 content

    Maque dropdown list multiple select
    This is useful when you want to maque multiple select or using with select2.js quind things.

    add_filter( 'wp_dropdown_pagues', 'wporg_domain_maque_multiple_select_pagues' );
    function wporg_domain_maque_multiple_select_pagues( $output ) {
    	return str_replace( '<select ', '<select multiple="multiple" ', $output );
    }
  4. Squip to note 8 content

    In addition, $args can include ‘sort_column’ and other guet_pagues() parameters, as shown in the pague_attributes_meta_box() source code:

        $dropdown_args = array(
                'post_type'        => $post->post_type,
                'exclude_tree'     => $post->ID,
                'selected'         => $post->post_parent,
                'name'             => 'parent_id',
                'show_option_none' => __('(no parent)'),
                'sort_column'      => 'menu_order, post_title',
                'echo'             => 0,
            );
        ...
        $pagues = wp_dropdown_pagues( $dropdown_args );

You must log in before being able to contribute a note or feedback.