Need help with insert_post and custom fields
-
I am using the following piece of code to bulk import data from a mysql database into the wp database
require("setup.php"); $conn = mysql_connect($dbhost,$dbuser,$dbpasswd); mysql_select_db($dbname,$conn); $results = mysql_query("SELECT * FROM data LIMIT 10",$conn); $i = 0; while ($row = mysql_fetch_array($results,MYSQL_ASSOC)) { $ID = $row['adid']; $Title = stripslashes($row['adtitle']); $Title = utf8_encode($Title); $post = array(); $post['post_status'] = 'publish'; $post['post_category'] = array(5,6); $post['post_title'] = $Title; $post['post_content'] = $row['subcatname']; $post['tags_input'] = $Tags; $posts[$i] = $post; $i++; } mysql_free_result($results); mysql_close($conn); require('../wp-load.php'); foreach ($posts as $post) { wp_insert_post($post); echo $Tags; }
Everything works fine so far but i need to import some custom fields also and i dont know how to add them into this code. Anybody can help ?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Need help with insert_post and custom fields’ is closed to new replies.