WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_List_Table::months_dropdown() protected WP 3.1.0

Displays a dropdown for filtering items in the list table by month.

Это метод класса: WP_List_Table{}

Возвращает

Null. Ничего.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->months_dropdown( $post_type );
$post_type(строка) (обязательный)
The post type.

Заметки

  • Global. wpdb. $wpdb WordPress database abstraction object.
  • Global. WP_Locale. $wp_locale WordPress date and time locale object.

Список изменений

С версии 3.1.0 Введена.

Код WP_List_Table::months_dropdown() WP 5.5.1

wp-admin/includes/class-wp-list-table.php
<?php
protected function months_dropdown( $post_type ) {
	global $wpdb, $wp_locale;

	/**
	 * Filters whether to remove the 'Months' drop-down from the post list table.
	 *
	 * @since 4.2.0
	 *
	 * @param bool   $disable   Whether to disable the drop-down. Default false.
	 * @param string $post_type The post type.
	 */
	if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) {
		return;
	}

	$extra_checks = "AND post_status != 'auto-draft'";
	if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) {
		$extra_checks .= " AND post_status != 'trash'";
	} elseif ( isset( $_GET['post_status'] ) ) {
		$extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] );
	}

	$months = $wpdb->get_results(
		$wpdb->prepare(
			"
		SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
		FROM $wpdb->posts
		WHERE post_type = %s
		$extra_checks
		ORDER BY post_date DESC
	",
			$post_type
		)
	);

	/**
	 * Filters the 'Months' drop-down results.
	 *
	 * @since 3.7.0
	 *
	 * @param object[] $months    Array of the months drop-down query results.
	 * @param string   $post_type The post type.
	 */
	$months = apply_filters( 'months_dropdown_results', $months, $post_type );

	$month_count = count( $months );

	if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) {
		return;
	}

	$m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
	?>
	<label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date' ); ?></label>
	<select name="m" id="filter-by-date">
		<option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option>
	<?php
	foreach ( $months as $arc_row ) {
		if ( 0 == $arc_row->year ) {
			continue;
		}

		$month = zeroise( $arc_row->month, 2 );
		$year  = $arc_row->year;

		printf(
			"<option %s value='%s'>%s</option>\n",
			selected( $m, $year . $month, false ),
			esc_attr( $arc_row->year . $month ),
			/* translators: 1: Month name, 2: 4-digit year. */
			sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
		);
	}
	?>
	</select>
	<?php
}