How to trigger algolia_update_post only when a certain post type is saved or updated

Hi, I’m currently integrating the wordpress plugin following the documentation (Quick Start | WordPress | Algolia)

I managed to set up the “wp algolia reindex_post” which work perfectly, but I start to struggle when I want my posts to be updated and send to algolia index.

The problem is that each time ANYTHING is saved in the wordpress admin, it is sent to algolia. I guess it’s because the add_action ‘save_post’ is triggered everytime anything is saved in Wordpress. For example, I’m creating new fields using acf, everytime I save something, it’s sent to algolia index, but I want to send to Algolia only when posts having a certain post type to be sent to the index. Where in this code can I do a post type check before sending to algolia :

function algolia_update_post($id, WP_Post $post, $update) {

if (wp_is_post_revision($id) || wp_is_post_autosave($id)) {

return$post;

}

global$algolia;

$record = (array) apply_filters($post->post_type.'_to_record', $post);

if (!isset($record['objectID'])) {

$record['objectID'] = implode('#', [$post->post_type, $post->ID]);

}

$index = $algolia->initIndex(

apply_filters('algolia_index_name', 'CAA-test')

);

if ('trash' == $post->post_status) {

$index->deleteObject($record['objectID']);

} else {

$index->saveObject($record);

}

return$post;

}

Can

I, somehow, check if the stuff saved in the wordpress admin is -

  1. A post, a page or a list of custom post type

  2. if the saved item is a post, send it to algolia index

Thank you