admin管理员组

文章数量:1389783

Here, I have some code which applies some indexing operations on an external service (Algolia). My purpose, is to index posts in a similar way, as described in their API documentation. For that cause, I have set up two action hooks:

add_action('save_post', 'algolia_save_post', 10, 3);

and

add_action('trashed_post','algolia_trash_post', 10, 1);

While this works as expected, I noticed that, in case metadata are altered, such as permalinks, the data are not updated in the index. I then tried the update_post_meta action hook:

add_action('update_post_meta', 'algolia_update_post_meta', 10, 4);

Which seems to do the job well. However, I suspect that update_post_meta is invoked both when metadata fields are altered, but also on save_post chain.

As I do not want to achieve a double, redundant indexing on article save I would like to ask, is the addition of the indexing code in the update_post_meta considered always on post save? In that case, I can remove the save_post hook and keep only this of meta. What I want to avoid, is the loss of index update in any case of the post update operations (excluding auto-save).

My local testing showed that, by adding the code only in the meta hook, everything works well and index gets updated on any field, yet I am not sure if there is an edge case I miss.

While this question involves the usage of an third-part vendor (Algolia), I believe it can be answered by a WordPress expert. Thank you in advance.

本文标签: postsIs updatepostmeta used when savepost action hook is invoked