1

I have found some topics related to this issue but no solution...

I have 2 different websites. I would like that, when I post some posts on the first one, they are automatically posted on the second one, including the featured image.
I tried using a plugin called "RSS Post Importer" but it doesn't get the featured image.

I did some research and found that a solution is to use fetch_feed and wp_insert_post and create a custom plugin (or function) using these two functions. Is there an easier/better way ?

2

I see you posted you found a solution, but just to add for others (and in case you're interested in another method):

You could hook Site A on the post's status change to Published to POST all relevant post data to an endpoint on Site B's api you've set up to function as a webhook.

(Authenticating can be done on this endpoint as well with a permissions callback that is called before the callback).

You can send/receive everything as json, or handle it like a form $_POST if you prefer, of course.

If you're just migrating, rather than keeping in sync, you could also reverse that flow and have Site B grab and process an endpoint on Site A that has all relevant posts.


I give a rough example in this WPSE answer after the heading "Import Bridge with WP-JSON API" if you want to look at some mocked up code on what I'm talking about.


I've also found this resource for WP_REST request class methods quite useful.

And of course there is the Wordpress wp-json developer handbook for a walkthrough.

0

You can create a custom plugin, but it'd take some work and you'd have to pay someone to do that. They could develop it either using RSS or the REST API. I recommend giving Pipes a try first though: https://wordpress.org/plugins/wp-pipes/. It's a great plugin that I've used in the past for this sort of thing.

  • I don't need to pay someone, I am a (junior) developper. I just wanted to know if anyone already achieved this with a simple solution. Anyway, I am developping the plugin, but since both sites are on the same server, I am using wpdb instead of an RSS feed – DevBob Jun 2 '17 at 11:24
0

I finally achieved it using the RSS Post Importer plugin. Then I used another plugin that allows to tweak the RSS feed on the first website to add the featured image in the content of the feed item. Then you just need to strip the first image from the content of the newly created post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.