WP_CLI\Iterators

Table::__construct()publicWP-CLI 1.0

Creates an iterator over a database table.

foreach( new Iterators\Table( array( 'table' => $wpdb->posts, 'fields' => array( 'ID', 'post_content' ) ) ) as $post ) {
	count_words_for( $post->ID, $post->post_content );
}
foreach( new Iterators\Table( array( 'table' => $wpdb->posts, 'where' => 'ID = 8 OR post_status = "publish"' ) ) as $post ) {
	…
}
foreach( new PostIterator( array( 'table' => $wpdb->posts, 'where' => array( 'post_status' => 'publish', 'post_date_gmt BETWEEN x AND y' ) ) ) as $post ) {
	…
}

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

Хуков нет.

Возвращает

null. Ничего.

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

$Table = new Table();
$Table->__construct( $args );
$args(массив)
Supported arguments:
php table – the name of the database table fields – an array of columns to get from the table, '*' is a valid value and the default where – conditions for filtering rows. Supports two formats: = string – this will be the where clause = array – each element is treated as a condition if it's positional, or as column => value if it's a key/value pair. In the latter case the value is automatically quoted and escaped append - add arbitrary extra SQL
По умолчанию: []

Код Table::__construct() WP-CLI 2.8.0-alpha

public function __construct( $args = [] ) {
	$defaults = [
		'fields'     => '*',
		'where'      => [],
		'append'     => '',
		'table'      => null,
		'chunk_size' => 500,
	];
	$table    = $args['table'];
	$args     = array_merge( $defaults, $args );

	$fields     = self::build_fields( $args['fields'] );
	$conditions = self::build_where_conditions( $args['where'] );
	$where_sql  = $conditions ? " WHERE $conditions" : '';
	$query      = "SELECT $fields FROM `$table` $where_sql {$args['append']}";

	parent::__construct( $query, $args['chunk_size'] );
}