我怎么能在wordpress帖子中导入json数据

时间:2015-08-30 09:30:03

标签: json wordpress

这是我的json数据,我想把它们放在wordpress中,我可以编写一个PHP脚本来读取json数据并将它们写在mysql表[ {"url": "http://www.test.com/page/111.html", "art_title": ["title111"], "art_content": ["the article content111"]}, {"url": "http://www.test.com/page/222.html", "art_title": ["title222"], "art_content": ["the article content222"]} ] 中,但对我来说更好的是什么我知道的。

json数据就像打击一样:

{{1}}

2 个答案:

答案 0 :(得分:2)

您需要json_decode您的JSON数据,在其上循环,然后使用wp_insert_post将帖子添加到WordPress(ref)。

注意:在使用wp_insert_post之前,您需要在文件中启动WordPress,您可以在自定义脚本中加入wp-load.php

答案 1 :(得分:0)

我最好的猜测是以语义正确的方式以编程方式将此json数据插入WordPress。最好的方法是制作你的json Objects帖子(或自定义底池类型,如果它们不适合使用像Humanmades Custom-Meta-Boxes这样的正常帖子参数来添加元数据或{{3} })。然后你可以通过wp_insert_post()将你的json数据作为新帖子插入数据库中(显然在执行验证之前检查帖子是否已经存在)。让我知道是否需要任何其他帮助或可以详细说明问题,以便我能给出更好的答案。