searchwp\results\entry\data
Since: 4.0.0
Table of Contents
This filter hook allows customization of the output data for each SearchWP result entry before it is passed to the SearchWP Template. It can be used to modify the displayed title, permalink, image, or content, as well as adjust the markup for specific object types such as posts, taxonomy terms, or users.
Parameters
| Type | Parameter | Default | Since | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Array |
$data
|
4.0.0 |
||||||||||||||||||||||
| Object | $result |
The SearchWP result entry object | 4.0.0 |
|||||||||||||||||||||
Examples
All hooks should be added to your custom SearchWP Customizations Plugin.
Append custom content for a specific post type.
| <?php | |
| // Customize SearchWP result entry data for the SearchWP template. | |
| add_filter( 'searchwp\results\entry\data', function( $data, $result ) { | |
| if ( $result instanceof \WP_Post && $result->post_type === 'product' ) { | |
| $data['content'] .= '<p>Free delivery available!</p>'; | |
| } | |
| return $data; | |
| }, 20, 2 ); |
Customize the image for taxonomy term results
| <?php | |
| add_filter( 'searchwp\results\entry\data', function( $data, $result ) { | |
| // Check if the result is a taxonomy term. | |
| if ( $result instanceof \WP_Term ) { | |
| // Replace default image HTML with a placeholder. | |
| $data['image_html'] = '<img src="http://place-hold.it/500x500" />'; | |
| } | |
| return $data; | |
| }, 20, 2 ); |
Add a label to user results
| <?php | |
| add_filter( 'searchwp\results\entry\data', function( $data, $result ) { | |
| if ( $result instanceof \WP_User ) { | |
| $data['title'] .= ' (User Profile)'; | |
| } | |
| return $data; | |
| }, 20, 2 ); |

