Convert WordPress MySQL data to .JSON file
-
Trying to figure out to create a .json file using a PHP script rather than a plugin (which doesn’t really create a JSON file on the server anyway). I’m using the following PHP code and it does create a .json file but with null data. Any idea how to properly do this?
<?php $con=mysql_connect("hostname","database_user","database_password") or die("Database connection failed"); if($con) { mysql_selectdb("database_wp",$con); } ?> <?php $data=array(); $qa=array(); $query=mysql_query("SELECT id, title, content FROM wp_posts ORDER BY id"); while($geteach=mysql_fetch_array($query)) { $id=$getputnam[0]; $title=$getputnam[1]; $content=$getputnam[2]; $qa[]=array('id'=> $id, 'title'=> $title, 'content'=> $content); } $data['qa']=$qa; $fp = fopen('myjson.json', 'w'); fwrite($fp, json_encode($data)); fclose($fp); ?>
- The topic ‘Convert WordPress MySQL data to .JSON file’ is closed to new replies.