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

WP_Date_Query::build_time_query() public WP 3.7.0

Builds a query string for comparing time values (hour, minute, second).

If just hour, minute, or second is set than a normal comparison will be done. However if multiple values are passed, a pseudo-decimal time will be created in order to be able to accurately compare against.

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

Хуков нет.

Возвращает

Строку/false. A query part or false on failure.

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

$WP_Date_Query = new WP_Date_Query();
$WP_Date_Query->build_time_query( $column, $compare, $hour, $minute, $second );
$column(строка) (обязательный)
The column to query against. Needs to be pre-validated!
$compare(строка) (обязательный)
The comparison operator. Needs to be pre-validated!
$hour(число/null)
An hour value (0-23).
По умолчанию: null
$minute(число/null)
A minute value (0-59).
По умолчанию: null
$second(число/null)
A second value (0-59).
По умолчанию: null

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

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

Код WP_Date_Query::build_time_query() WP 5.5.1

<?php
public function build_time_query( $column, $compare, $hour = null, $minute = null, $second = null ) {
	global $wpdb;

	// Have to have at least one.
	if ( ! isset( $hour ) && ! isset( $minute ) && ! isset( $second ) ) {
		return false;
	}

	// Complex combined queries aren't supported for multi-value queries.
	if ( in_array( $compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ), true ) ) {
		$return = array();

		$value = $this->build_value( $compare, $hour );
		if ( false !== $value ) {
			$return[] = "HOUR( $column ) $compare $value";
		}

		$value = $this->build_value( $compare, $minute );
		if ( false !== $value ) {
			$return[] = "MINUTE( $column ) $compare $value";
		}

		$value = $this->build_value( $compare, $second );
		if ( false !== $value ) {
			$return[] = "SECOND( $column ) $compare $value";
		}

		return implode( ' AND ', $return );
	}

	// Cases where just one unit is set.
	if ( isset( $hour ) && ! isset( $minute ) && ! isset( $second ) ) {
		$value = $this->build_value( $compare, $hour );
		if ( false !== $value ) {
			return "HOUR( $column ) $compare $value";
		}
	} elseif ( ! isset( $hour ) && isset( $minute ) && ! isset( $second ) ) {
		$value = $this->build_value( $compare, $minute );
		if ( false !== $value ) {
			return "MINUTE( $column ) $compare $value";
		}
	} elseif ( ! isset( $hour ) && ! isset( $minute ) && isset( $second ) ) {
		$value = $this->build_value( $compare, $second );
		if ( false !== $value ) {
			return "SECOND( $column ) $compare $value";
		}
	}

	// Single units were already handled. Since hour & second isn't allowed, minute must to be set.
	if ( ! isset( $minute ) ) {
		return false;
	}

	$format = '';
	$time   = '';

	// Hour.
	if ( null !== $hour ) {
		$format .= '%H.';
		$time   .= sprintf( '%02d', $hour ) . '.';
	} else {
		$format .= '0.';
		$time   .= '0.';
	}

	// Minute.
	$format .= '%i';
	$time   .= sprintf( '%02d', $minute );

	if ( isset( $second ) ) {
		$format .= '%s';
		$time   .= sprintf( '%02d', $second );
	}

	return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );
}