asp_result_groups

Search results when the results grouping feature is enabled

Accessing the results groups when the results grouping is enabled.

apply_filters('asp_result_groups', array $groups, int $id, array $args);

Parameters

  • $groups(array) - Array containing the results grouped

  • $id(int) - Search instance ID

  • $args (array) - Search arguments

Usage

add_filter( 'asp_result_groups', 'asp_result_groups_modify', 10, 1 );
function asp_result_groups_modify( $groups) {
	foreach ($groups as $slug=>&$group) {
		/**
		 * $slug (string) = 'group_slug',
		 * $group (array) [
		 *      'title' => 'Group header title',
		 * 			'items' => array(...) // The actual results
		 * ]
		 **/
		if ( $group['title'] == 'Group title' ) {
			// Change the group title
			$group['title'] == 'Modified group title';
			
			// Unset items from group where post ID is 123
			foreach ( $group['items'] as $k=>&$r ) {
				if ( $r->id == 123 ) {
					unset($group['items'][$k]);
				}
			}
		}
	}

	return $groups ;
}

Last updated

Copyright Ernest Marcinko