benecaster_ai_search_result_fields
Filters which parts of each result one benecaster_ai_search box shows: any of title, date and excerpt. The default is all three, and [ 'title', 'date' ] for placement="sidebar". title is always kept (it is the link), and anything else is dropped.
The answer is written into the box as data-fields. The search route still returns every field, so this changes what is shown, not what is sent.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$fields |
array |
— | Any of `title`, `date`, `excerpt` |
$placement |
string |
— | `full-page`, `sidebar` or `modal` |
$atts |
array |
— | The box's resolved attributes |
Returns:
array
Example
// Show excerpts in sidebar boxes too, but never dates in a modal.
add_filter( 'benecaster_ai_search_result_fields', function ( array $fields, string $placement ): array {
if ( 'sidebar' === $placement ) {
return [ 'title', 'excerpt' ];
}
return 'modal' === $placement ? array_values( array_diff( $fields, [ 'date' ] ) ) : $fields;
}, 10, 2 );
Notes
For each placement's look, style .benecaster-ai-search--{placement} in your theme. Walkthrough: Style the AI Search box's placements, or change what their results show.
Affects
- [benecaster_ai_search] shortcode
Need this built rather than just documented? See our services →