2014-10-07 37 views
0

嗨我包含多個值和鍵的多個JSON文件,我希望導入它們並映射2個值/鍵以成爲多個Wordpress頁面的標題和內容。如何將JSON字段導入Wordpress頁面? (將2個字段映射到標題和內容)

這裏是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數據庫。

非常感謝您的時間和幫助。

回答

0

如果你上傳到自己的文件夾:

$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數組。如果所有文件格式不同,您將遇到問題!

+0

json文件在我的電腦上,我想將內容導入到遠程的Wordpress數據庫。 – Gab 2014-10-07 21:52:43

+0

你在說什麼文件?這是一次性完成的行動嗎?顯然你會需要他們在你的服務器上工作,不管你是ftp還是使用表單上傳它們都會在方法上有所作爲。 – David 2014-10-07 21:59:36

+0

我有60-80頁......我可以FTP他們或任何。你有什麼建議?一次行動。 – Gab 2014-10-07 22:05:34

相關問題