I'm using this plugin (FantasticElasticSearch) to index content when it's published. So far it was strightforward and an easy task but, now that I tried to index a flag saying if a post is sticky, I'm having trouble and it's being impossible.
I'm changing the addOrUpdate function of the plugin to my profit, I'm adding some data (featured image, featured video...) and as I said I want to index if a post is sticky. The problem is that the database is not updated in the index moment, and I don't know how to hook to that event.
This is what's happening now:
- I publish a post, non-sticky.
- I check if the post is sticky to add that information to the index, so far all is good and it's indexed well (as a non-sticky post is_sticky returns false).
- I edit the post and turn it to an Sticky post. When I check if the post is sticky it returns false again, as if it wasnt updated in the database yet.
So, where do I have to hook? Can I force the update of the database with the sticky/nonsticky information with some function?
The function (addOrUpdate) that I'm rewritting is the one that's in this file.
I turned it into something like this:
static function addOrUpdate($post){
$type = self::_index(true)->getType($post->post_type);
$data = self::_build_document($post);
//filling $data with extra fields I'd like to index
$data['is_sticky'] = is_sticky();
//now the document is added to elastic.
$type->addDocument(new \Elastica\Document($post->ID, $data));
}
The addOrUpdate function hooks into the save_post event as you can see in the hooks.php file.
I'm still unable to get this working, I'd aprecciate any help you could give me on this matter. By the way, I already tried Pat J's method (is_sticky with Id post as a parameter, but I'm in the loop as I'm in the save_post action).
Finally solved it by looking in the $_POST array. $_POST['sticky'] is only informed when a POST is (or is being made) sticky.