ACF::posts_wherepublicACF 5.8.1

Filters the $where clause allowing for custom WP_Query args.

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

Хуков нет.

Возвращает

Строку.

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

$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.4.2

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' );
	$post_type_key = $wp_query->get( 'acf_post_type_key' );
	$taxonomy_key  = $wp_query->get( 'acf_taxonomy_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 );
	}

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

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

	return $where;
}