WordPress record filter?


I have managed to get a custom Term filter to work fine however, I am unable to create a custom post record.

This is my function below. I get an error when I try to re-index any posts. I can not figure out what’s cause it not to index.

function test( array $record, WP_Post $post ) {
        $record['rating'] = '5.5';

    return $record;

add_filter( 'algolia_post_records', 'test', 10, 2 );

I get a popup error stating:

An error occurred:

Any help would be great.


Managed to get it to work this way:

function test( array $shared_attributes, WP_Post $post ) {
        $shared_attributes['rating'] = '5.5';

    return $shared_attributes;

add_filter( 'algolia_post_reviews_shared_attributes', 'test', 10, 2 );

But not sure why not able using algolia_post_records?

Hey @Mack,

Thanks for the feedback,

The docs about that specific filter you first used was unclear. I just adjusted the filter parameters: https://github.com/algolia/algoliasearch-wordpress/pull/686

The algolia_post_records callback will receive as first parameter an array of records for a given post.
As a result, using shared attributes is a better move :wink:

Thanks for updating. Docs overall are quite good but might make it easier having an example for each of you guys got time for it.


1 Like