wpfts_index_post_finish (Action)

The wpfts_index_post_finish hook in WP Fast Total Search is called at the very end of the individual post indexing process, after all data has been extracted and prepared for addition to the index, and before this data is written to the database.

When to Use

This hook is useful for the following purposes:

  • Performing additional processing or modification of the data prepared for indexing ($chunks) before it is written to the database.
  • Cleaning up resources initialized in the wpfts_index_post_start hook.
  • Logging or debugging indexing results.
  • Adding data to the index from external sources related to the given post.

Arguments

  • $chunks (array): An array of data prepared for indexing. This array has already been modified by the wpfts_index_post filter and contains the final data set for indexing. Important: This argument is passed by reference (&), therefore changes made to the $chunks array will not be saved, as this hook is called after the wpfts_index_post filter, and the data has already been prepared for writing. However, you can use this array to obtain information, for example, for logging. If you need to modify the data before indexing, use the wpfts_index_post filter.
  • $post (object): A WP_Post object representing the post being indexed.
  • $wpfts_core (object): The plugin core object WPFTS_Core. Provides access to all plugin methods and properties.

Return Value

  • $chunks (array): The modified data array. Although changes made to $chunks will not affect indexing, the handler function must return the $chunks array.

Example

/**
 * Logs the size of the indexed data.
 */
add_filter('wpfts_index_post_finish', 'my_wpfts_index_post_finish_handler', 10, 3);
function my_wpfts_index_post_finish_handler($chunks, $post, $wpfts_core) {
 
	$data_size = 0;
	foreach ($chunks as $chunk) {
		$data_size += strlen($chunk);
	}
 
    $wpfts_core->log('Post ID: ' . $post->ID . ', Data size: ' . $data_size . ' bytes');
    return $chunks;
 
}

Important Notes

  • This hook is called for each indexed post. The code inside the handler should be efficient.
  • Avoid outputting any information to the screen inside this hook’s handler, as indexing is performed in the background.

The wpfts_index_post_finish hook provides developers with the ability to perform final actions after indexing each post.