Filter and Hooks

PHP code to Import the POST from one website to another

1. Create a folder in the root directory of the site i.e PARENT_SITE. I have created services folder in the root directory and created the php file named news.php

2. Include wp-load.php the files so that we could use all the WordPress available functions

3. Write a code that encode all the posts/contents related to ‘post_type’=>’post’. We can replace ‘post_type’ => ‘post’ by any other custom post types

We can check the encoded post contents in the Url : http://PARENT_SITE/services/news.php

4. Create a folder in the root directory of the site, I call it AS CHILD_SITE where we want to import the all the contents of posts from the PARENT_SITE. I have created app folder in the root directory of CHILD_SITE and created the php file named import-news.php inside the folder:

5.   I have created custom posts and two meta fields , using acf to save the thumbnail  and permalink of imported posts

p.s. I   like to display the thumbnail of news directly from the source instead of saving it in my site and I  might need the source of the  news in the future

6. I have created the field from so that user can input the url from where they can get the json encoded posts to be imported

7.  I have created Importer class that handles the import part. So that I can update the post_type and source link of import  & use the same code in other Projects. To parse the json encoded contents  I have used Guzzle

9. Last but not the list,  run the import file in the CHILD_SITE to import the news  : http://CHILD_SITE/app/import-news.php

P.S. The process is long and I haven’t displayed any screen-shots so that you could try it on your own; provided the full code 😛

Hits: 9

Standard