SearchWP Documentation

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

searchwp_live_search_results_entry_data

Since: 4.0.0

Table of Contents

This filter hook allows you to customize the data for each SearchWP result entry before it is rendered in the SearchWP Live Search results template.

It is specifically intended for Live Search output and enables developers to modify result properties such as the title, permalink, image markup, and excerpt content. 

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 e.g., post type name like 'post', 'page', 'product' etc., 'user' or 'taxonomy-term.
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.

Include product SKU in Live Search result content

This example appends the WooCommerce product SKU to the result content when the entry is a product.

<?php
add_filter( 'searchwp_live_search_results_entry_data', function( $data, $result ) {
if ( $result instanceof \WP_Post && $result->post_type === 'product' ) {
$sku = get_post_meta( $result->ID, '_sku', true );
if ( ! empty( $sku ) ) {
$data['content'] .= '<p><strong>SKU:</strong> ' . esc_html( $sku ) . '</p>';
}
}
return $data;
}, 20, 2 );

How to use this code

Update media attachment results to link to their parent post

By default, media attachments may link to their attachment page. This example updates the permalink so Live Search results for media posts point to their parent post url instead.

 

<?php
add_filter( 'searchwp_live_search_results_entry_data', function( $data, $result ) {
if ( $result instanceof \WP_Post && $result->post_type === 'attachment' ) {
$parent_id = wp_get_post_parent_id( $result->ID );
if ( $parent_id ) {
$data['permalink'] = get_permalink( $parent_id );
}
}
return $data;
}, 20, 2 );

How to use this code