ACF::posts_where()publicACF 5.8.1

Filters the $where clause allowing for custom WP_Query args.

Метод класса: ACF{}

Хуков нет.

Возвращает

WP_Query. $wp_query The query object.

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

$ACF = new ACF();
$ACF->posts_where( $where, $wp_query );
$where(строка) (обязательный)
The WHERE clause.
$wp_query(WP_Query) (обязательный)
The query object.

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

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

Код ACF::posts_where() ACF 6.0.4

public function posts_where( $where, $wp_query ) {
	global $wpdb;

	$field_key  = $wp_query->get( 'acf_field_key' );
	$field_name = $wp_query->get( 'acf_field_name' );
	$group_key  = $wp_query->get( 'acf_group_key' );

	// Add custom "acf_field_key" arg.
	if ( $field_key ) {
		$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $field_key );
	}

	// Add custom "acf_field_name" arg.
	if ( $field_name ) {
		$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_excerpt = %s", $field_name );
	}

	// Add custom "acf_group_key" arg.
	if ( $group_key ) {
		$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_name = %s", $group_key );
	}

	// Return.
	return $where;
}