0

I have a website it's contains a lot of news, i have to list this news in one PHP file , now i want to insert each news in wordPress as a Post.. what is the best practice way to do that (the news are more than 100 articles) , how can i build manually the XML file so i can import it in WordPress ? or what is the post insert function , so i can call it in PHP file ..?

the news are here : https://www.steuerlex24.de/steuerkanzlei-koerfer/information_steuer-news

there is an API to export the news in XML file.

Thanks a lot

  • One way would be to grab the XML file, turn it into an object using something like PHP's simplexml_load_string, and then iterate over the object to insert your posts in the way Pim describes in his answer. – Michael Sep 28 '18 at 13:49
0

The PHP way

If you want to use PHP, you can use wp_insert_post to insert posts programatically. Basically you want to provide an array of post information (title, content, date...). You can read more about it here: https://developer.wordpress.org/reference/functions/wp_insert_post/

But the problem is you should not run that function to import all 100 posts. I used to solve the same problem: Migrate 34k posts from old site to new site using WordPress. Here is what I did:

  • Write a PHP script to crawl the post URLs of target site. I wrap it in a Page template. I use Simple HTML DOM to extract data from page. I append the result to the page itself.
  • Still on that page, after getting all URLs I need, I use Ajax to insert post one by one. Use Simple HTML DOM to extract data, then use wp_insert_post to insert post to database with the crawled data
    • Get URL from the list append in the previous step
    • Use Simple HTML DOM to extract data from that URL
    • Use wp_insert_post to create post with extracted data.
    • Repeat that action until all done.

The CSV way

IMO, build a WordPress xml file to import is hard. You can think about a simpler alternative choice is CSV. Build a CSV file is more straight forward and simpler. Then you can use a CSV import plugin to create posts on your new site.

| improve this answer | |
0

You can use wp_insert_post().

$args = array (
   'post_title' => $your_title,
   'post_content' => $your_content,
   'post_status' => 'publish'
)

$post_id = wp_insert_post($args);
| improve this answer | |

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.