Quantcast
Channel: Question and Answer » meta-query
Viewing all articles
Browse latest Browse all 36

how to insert post in wordpress with meta

$
0
0

How can I get the data from a table into the wordpress posts?
I use this code but not corectly works…

if (isset($_GET['SQL'])){
global $wpdb;
$num;
$rows = $wpdb->get_results("SELECT * from doctor");
foreach ($rows as $row ){
$num++;
$my_post = array(
     'post_title' => $row->Name,
     'post_content' => '',
     'post_status' => 'publish',
     'post_type' => 'doctor',
  );
$post_id = wp_insert_post($my_post);
add_post_meta($post_id, 'City', $row->City, true);
add_post_meta($post_id, 'Phone', $row->Phone, true);
add_post_meta($post_id, 'Specialty', $row->Specialty, true);
add_post_meta($post_id, 'ID', $row->ID, true);
add_post_meta($post_id, 'Address', $row->Address, true);
add_post_meta($post_id, 'Date', $row->Date, true);

}
echo "hi";
}

Viewing all articles
Browse latest Browse all 36

Trending Articles