如何将JSON字段导入Wordpress页面?(将2个字段映射到标题和内容)


How can I import JSON fields to a Wordpress page? (mapping 2 fields to title and content)

Hi我有多个JSON文件,其中包含多个值和键,我希望导入它们并映射2个值/键,以成为多个Wordpress页面的标题和内容。

下面是一个JSON文件示例:

[
    {
        "name": "Content",
        "type": "group",
        "variables": [
            {
                "name": "Title",
                "type": "string",
                "value": "The title that will become the content in the Wordpress page."
            },
            {
                "name": "Description",
                "type": "string",
                "value": ""
            },
            {
                "name": "Promoted",
                "type": "boolean",
                "value": false
            },
            {
                "name": "Main",
                "type": "content",
                "value": {
                    "text": "<h2>Some text here<br><'/h2><p>The content that will become the content in the Wordpress page.<'/p>",
                    "components": [],
                    "images": []
                }
            },
            {
                "name": "Top Content",
                "type": "content",
                "value": {
                    "text": "",
                    "components": [],
                    "images": []
                }
            }
        ]
    }
]

我应该如何继续?json文件在我的计算机上,我想将内容导入远程Wordpress数据库。

非常感谢您的时间和帮助。

如果您将它们上传到它们自己的文件夹中:

 $files= scandir('your directory path'); 
 foreach($files as $file):
      $json= json_decode( file_get_contents($file) );
      // create your post array here... 
      // e.g. $content= $json['content']; 
      wp_insert_post($post);
 endforeach;
 $array= json_decode($json);

你还有一些工作要做,你需要弄清楚你想要插入,查找wp_insert_post,然后尝试访问$json数组中的内容。如果所有的文件都有不同的格式,你会在这里遇到问题!

相关文章: