Nikau
Nikau

Reputation: 51

Wordpress - Publish post with featured image at same time via PHP

I am publishing to Wordpress via PHP, as follows.

Problem:

When creating the Post, there is a Plugin (SNAP autoposter) that will automatically publish it on Facebook. But, as obvious, it does not wait until the featured image is attached.

Question:

How should I proceed to publish the post with an already assigned attachment?

Thanks a lot for your help :)

Upvotes: 0

Views: 137

Answers (1)

Mathew Tinsley
Mathew Tinsley

Reputation: 6976

Don't publish the post until the attachment has been added.

  • Set the post_status to draft when you call wp_insert_post.
  • Add the attachment to the draft.
  • Use wp_publish_post to publish the post.

If the plugin is setup correctly, it will be listening for the status transition to publish.

Upvotes: 1

Related Questions