Unable to sync post using a standalone script
-
I have a WordPress site with around 70,000 news articles with a custom post type. Occasionally, we have a problem with some scheduled posts missing their publication and we use a script to trigger the publication with a call publish_post. While the posts get published, they don’t get synced with Elastic. So I tried to explicitly sync the articles using:
\ElasticPress\Indexables::factory()->get( 'post' )->index( ((int)$argv[1]), true );
This too doesn’t work. When I tried triggering an update with wp_update_post, I can see pre_ep_index_sync_queue being called but the sync does not happen. I implemented ep_sync_insert_permissions_bypass too to ensure that the sync is not being blocked because I’m running this from a standalone script. Here’s what I have now:
<?php require( '/home/ubuntu/website/wordpress/wp-load.php' ); function bypass_elastic_permissions($bypass) { echo("In bypass check.\n"); var_dump($bypass); return true; } add_filter('ep_sync_insert_permissions_bypass', 'bypass_elastic_permissions', 100); $args = array( 'ID' => (int)$argv[1], 'post_status' => 'publish' ); wp_update_post($args, false, true);
The sync works if I use the WordPress UI to update the post without making any changes. The script doesn’t work. Any idea why the sync doesn’t happen with the standalone script? Is there anything other than the permission bypass that I should implement in the script?
- The topic ‘Unable to sync post using a standalone script’ is closed to new replies.