Automattic\WooCommerce\Api\Pagination

IdCursorFilter::applypublic staticWC 1.0

Filter callback for posts_where. Appends cursor conditions when the corresponding query vars are set on the WP_Query; returns the input clause unchanged otherwise.

Method of the class: IdCursorFilter{}

No Hooks.

Returns

String. The modified WHERE clause.

Usage

$result = IdCursorFilter::apply( $where, $query ): string;
$where(string) (required)
SQL WHERE clause being built.
$query(WP_Query) (required)
The WP_Query being prepared.

IdCursorFilter::apply() code WC 10.9.1

public static function apply( string $where, \WP_Query $query ): string {
	$after  = (int) $query->get( self::AFTER_ID );
	$before = (int) $query->get( self::BEFORE_ID );

	if ( $after <= 0 && $before <= 0 ) {
		return $where;
	}

	global $wpdb;
	if ( $after > 0 ) {
		$where .= $wpdb->prepare( " AND {$wpdb->posts}.ID > %d", $after );
	}
	if ( $before > 0 ) {
		$where .= $wpdb->prepare( " AND {$wpdb->posts}.ID < %d", $before );
	}
	return $where;
}