
I have a Post Object field that allows for multiple links to 1 custom post type.
I’ve added some actions to watch for status transitions using this pattern.
During this transition I am sending some data over to Algolia, I’ve noticed however, that I need to click “Update” twice for the changes made to my Post Object field to update properly in Algolia. Other fields, Text, Gallery, Textarea updates immediately.
A shorted code snippet of what I am doing below;
add_action('publish_product', 'on_product_publish', 10, 2);
function on_product_publish($ID, WP_Post $product)
{
$tags = get_field('product-tags', $ID);
$record = array();
if ($tags) {
$record["tags"] = array_map(function (WP_Post $tag) {
return $tag->post_title;
}, $tags);
}
// Do the indexing here
}
Not sure why this field specifically has this “lag” when using this transition. Maybe using get_field for this field type isn’t the best idea? I’ve also tried changing the return type from Post Object to Post ID but that didn’t seem to make a difference.
Any help is appreciated.