Hi,
Is it possible to enable Ivory Search’s AJAX functionality to include BuddyPress activity content in the search results?
We’re currently using BuddyPress Global Search alongside Ivory Search. When a user presses enter after typing a query, the full search results page correctly displays activity content. However, the AJAX live search dropdown does not include any activity results.
I attempted to use the following snippet to include activity in the AJAX results, but it doesn’t seem to be working as expected:
// Add BuddyPress activity to Ajax search
add_filter( ‘bp_global_search_ajax_results’, ‘include_activity_in_ajax’, 10, 2 );
function include_activity_in_ajax( $results, $search_term ) {
// Safety check to ensure BuddyPress is active
if ( ! function_exists( ‘bp_has_activities’ ) ) {
return $results;
}
// Query BuddyPress activity content
if ( bp_has_activities( array(
‘search_terms’ => esc_attr( $search_term ),
‘per_page’ => 5
) ) ) {
while ( bp_activities() ) {
bp_the_activity();
$results[] = array(
‘title’ => wp_strip_all_tags( bp_get_activity_content_body() ),
‘url’ => bp_get_activity_thread_permalink(),
‘type’ => ‘activity’,
);
}
}
return $results;
}