wpfts_se_data (Filter)

The wpfts_se_data filter in WP Fast Total Search allows developers to modify the data used to create Smart Excerpts before HTML code generation. This enables altering or adding information displayed in search results along with the excerpt, such as relevance, file size (for attachments), links, and other parameters.

When to Use

This filter can be useful if you need to:

  • Change the displayed relevance.
  • Add or modify the download link for attachments.
  • Add additional information to the search results, such as publication date or author.

Arguments

  • $r1 (array): An array of data used to create Smart Excerpts. Contains the following keys:
    • is_excerpt_text (bool): Whether to display the excerpt text.
    • excerpt_text (string): The excerpt text.
    • is_not_found_words (bool): Whether to display not found words.
    • not_found_words (array): An array of not found words.
    • is_score (bool): Whether to display relevance.
    • score (float): The relevance value.
    • is_attachment (bool): Whether the post is an attachment.
    • is_filesize (bool): Whether to display the file size (for attachments).
    • is_direct_link (bool): Whether to use a direct link to the attachment file.
    • filesize (int): The file size in bytes (for attachments).
    • link (string): The link to the attachment file.
    • is_demo (bool): A demo mode flag.
  • $post (array): An array of post data.

Return Value

  • $r1 (array): The modified data array.

Example (Changing Relevance Display Format)

add_filter('wpfts_se_data', 'change_score_format', 10, 2);
 
function change_score_format($r1, $post)
{
	if ($r1['is_score']) {
		$r1['score'] = round($r1['score'] * 100) . '%'; // Display relevance as a percentage.
	}
	return $r1;
}

Important Notes

  • The wpfts_se_data filter is called before Smart Excerpts HTML code generation.
  • Changes made to the $r1 array will be reflected in the search results.

This filter provides developers with the flexibility to customize the data displayed in Smart Excerpts in WP Fast Total Search.