SearchWP Documentation

View the installation guide, browse the Knowledge Base, find out about SearchWP’s many hooks

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
Key Type Value
id Integer Entry id e.g., post id, term id or user id etc.
type String Entry type
title String Entry title
permalink String Entry url
image_html String Entry image element
content String Entry excerpt
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 );

How to use this code

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 );

How to use this code

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 );

How to use this code