Skip to content
Docs
Get RestroPress

Filter

rpress_reset_add_queries_{$type}

Updated
On this page

Filters the SQL queries run when resetting a custom item group.

The dynamic part is the group name returned by rpress_reset_item_type. It only runs for groups other than customers, fooditems and other. The callback receives the list of queries collected so far and a comma-separated string of item IDs for the group, and returns the list with extra queries added. Each query is executed with $wpdb->query(), so queries must be fully prepared.

Parameters#

ParameterTypeDescription
$sqlarrayList of SQL query strings to run for this step.
$idsstringComma-separated IDs of the items in this group.

Return value#

array. The list of SQL queries to run.

Example#

function my_reset_queries( $sql, $ids ) {
	global $wpdb;
	$id_list = implode( ',', array_map( 'absint', explode( ',', $ids ) ) );
	$sql[] = "DELETE FROM {$wpdb->postmeta} WHERE post_id IN ($id_list)";
	return $sql;
}
add_filter( 'rpress_reset_add_queries_my_custom_log', 'my_reset_queries', 10, 2 );

Notes#

The IDs are absint values joined into a string; sanitise them again before building queries. Queries run without further preparation.

Source#

Applied in:

  • includes/admin/tools/class-rpress-tools-reset-stats.php (line 140), in RPRESS_Tools_Reset_Stats::get_data()

See also#

Was this page helpful?