WP_CLI\Iterators

Query::__construct()publicWP-CLI 1.0

Creates a new query iterator

This will loop over all users, but will retrieve them 100 by 100:

foreach( new Iterators\Query( 'SELECT * FROM users', 100 ) as $user ) {
	tickle( $user );
}

Method of the class: Query{}

No Hooks.

Return

null. Nothing (null).

Usage

$Query = new Query();
$Query->__construct( $query, $chunk_size );
$query(string) (required)
The query as a string. It shouldn't include any LIMIT clauses
$chunk_size(int)
How many rows to retrieve at once; default value is 500 (optional)
Default: 500

Query::__construct() code WP-CLI 2.8.0-alpha

public function __construct( $query, $chunk_size = 500 ) {
	$this->query = $query;

	$this->count_query = preg_replace( '/^.*? FROM /', 'SELECT COUNT(*) FROM ', $query, 1, $replacements );
	if ( 1 !== $replacements ) {
		$this->count_query = '';
	}

	$this->chunk_size = $chunk_size;

	$this->db = $GLOBALS['wpdb'];
}