SearchRovr Documentation

Developer Features (Hooks and Filters

SearchRovr provides a set of hooks and filters that allow developers to extend, customize, and fine-tune the behavior of indexing and search. These are especially useful if you want to:

  • Add custom fields or metadata to the search index
  • Modify queries before they’re sent to the SearchRovr API
  • Adjust the formatting of search results before display
  • Integrate SearchRovr results into custom workflows

Action Hooks

searchrovr_before_index

Description: Fires before a piece of content is sent to the indexer.
Parameters:

  • $post_id (int) The WordPress post ID being indexed.
add_action( 'searchrovr_before_index', function( $post_id ) {
    // Example: log or modify post data before indexing
    error_log( "About to index post: " . $post_id );
});
Code language: PHP (php)

searchrovr_after_index

Description: Fires after a post or CPT has been successfully indexed.
Parameters:

  • $post_id (int) The WordPress post ID.
  • $response (array) API response data.
add_action( 'searchrovr_after_index', function( $post_id, $response ) {
    // Example: trigger related workflows after indexing
    do_action( 'my_custom_index_hook', $post_id, $response );
}, 10, 2 );
Code language: PHP (php)

Filters

searchrovr_index_data

Description: Filter the data that gets sent to SearchRovr for indexing.
Parameters:

  • $data (array) The content array (title, content, meta, etc).
  • $post_id (int) The WordPress post ID.
add_filter( 'searchrovr_index_data', function( $data, $post_id ) {
    // Example: add a custom ACF field to the index
    $data['custom_field'] = get_field( 'custom_field', $post_id );
    return $data;
}, 10, 2 );
Code language: PHP (php)

searchrovr_results_output

Description: Filter the final search results before they’re rendered on the frontend.
Parameters:

  • $results (array) Array of search result objects.
  • $query (string) The original search query.
add_filter( 'searchrovr_results_output', function( $results, $query ) {
    // Example: append "sponsored content" item to results
    $results[] = [
        'title' => 'Check out our premium resources',
        'url'   => '/premium-resources',
        'type'  => 'promo'
    ];
    return $results;
}, 10, 2 );
Code language: PHP (php)

Best Practices

  • Always check for required fields before modifying $data.
  • Use unique priorities (second parameter in add_action/add_filter) if your site uses multiple customizations.
  • Keep API payloads lean—avoid adding unnecessary fields to indexed content.
  • Test your hooks in staging before applying them to production.

Coming Soon

  • Additional filters for search ranking adjustments
  • Hooks for integrating third-party analytics
  • Filters for customizing dashboard analytics export