I'm importing some static pages into my WP website via code, and there's 2 issues I can't find any solution for.
Here's my insertion code:
$data = getPost(1);
// details for the post we're about to insert
$my_post = array(
'post_title' => $data['page_title'],
'post_date' => date('Y-m-d H:i:s',strtotime($data['date'])),
'post_date_gmt' => date('Y-m-d H:i:s',strtotime($data['date'])),
'post_content' => '<p>' . $data['intro'] . '</p>' . $data['body'],
'post_status' => 'publish',
//'post_category' => (!empty($cats[$data['category']]) ? $cats[$data['category']] : 1),
'post_author' => (!empty($users[$data['author']]) ? $users[$data['author']] : 9),
'post_name' => $data['slug'],
'post_type' => 'post'
);
If you ever wonder what's inside of $data, here it is:
Array ( [post_title] => Gutscheine bei Bingo3X gewinnen [post_date] => 2013-12-08 00:00:00 [post_date_gmt] => 2013-12-08 00:00:00 [post_content] => Nicht nur Geld gewinnen macht Spaß, sondern Gutscheine können ebenfalls ihren Vorteil haben. So gibt es mit der Pouch-A-Vouch Aktion bei Bingo3X zurzeit Gutscheine im Wert von 30 £ gewinnen.
Nicht nur Geld gewinnen macht Spaß, sondern Gutscheine können ebenfalls ihren Vorteil haben. So gibt es mit der Pouch-A-Vouch Aktion bei Bingo3X zurzeit Gutscheine im Wert von 30 £ gewinnen.
[post_status] => publish [post_author] => 9 [post_name] => gutscheine-bei-bingo3x-gewinnen [post_type] => post )
According to http://codex.wordpress.org/Function_Reference/wp_insert_post "post_name" will create the slug for the post (link to it), whenever I import this data, it adds the post correctly, but appends some weird number to the end of the slug, f.e it can be: mysite.com/2013/10/08/gutscheine-bei-bingo3x-gewinnen-5 <--- THAT -5 is coming from nowhere.. Any ideas? :)
Bigger issue. How do I add featured_image via code? I have URL (or I can have the image located locally, I have sizes, but I don't find how to insert it with the post. Some kind of add_post_meta or wp_set_object_terms can help? But I'm not sure what to write there...
Thanks!!