• Hi, I think I may be asking too much here but let’s try anyway.

    I have written a plugin that pulls data from YouTube and Vimeo, downloads a thumbnail, writes a post (back dated to when the video was posted on Vimeo/Youtube) then attaches the thumbnail. This works great but as I want it to appear on Facebook, I am using the Jetpack publicize feature.

    That also works but only rarely does it attach the image to the Facebook post. Occasionally it does but not often. I have tried re-ordering so the post is created in draft, the image attached, then the post is amended to published. This did not improve the situation and only resulted in adding two entries per post into the database.

    I am thinking that the problem is that it’s happening too fast. Is there any way to programatically delay the publicizing of the post by a few seconds, minutes etc after publishing?

    Alternatively is there a way to schedule a post to the blog and also back-date it when it gets on there?

    Blog site: https://rollingmedia.net
    Facebook: https://www.facebook.com/RollingMediaFeed

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I suppose you could insert a sleep() call somewhere between when the thumbnail is attached and when the post is publicized. You’d want to do this from within a filter or action callback so your delay remains sustainable.

    You should be able to back date posts using the ‘wp_insert_post_data’ filter. I’m assuming there would be some way of detecting that a scheduled post is being saved from the passed arguments.

    Another possibility would be to schedule an event to run periodically using wp_schedule_event(). The event would be the publicizing of any posts inserted in the last recent period. The back dating would need to wait until this event so an accurate query of recent insertions could be run. This means the eventual back date value would need to be managed elsewhere up to this point.

    It may be Facebook is getting cached data, so that instead of a delay, ensuring the cache is up to date may be what is required. See Class Reference/WP Object Cache.

Viewing 1 replies (of 1 total)
  • The topic ‘wp_insert_post, Jetpack publicize and images’ is closed to new replies.