php - How to save/update array of posts in Wordpress at once? -


i creating own plugin , have created array called $titles_arr

and looks this:

array (     [0] =>                  acrobotics wants kickstart smarter cities smart citizen environment sensors              [1] =>                  leaked memo shows barnes & noble bringing web browser , email simple touch ereaders in june                 [2] =>                  how cheap genetic testing complicates cancer screening                [3] =>                  android’s design principles , calculus of human pleasure response              [4] =>                  iterations: how tech hedge funds , investment banks make sense of apple’s share buybacks               [5] =>                  yahoo board has approved $1.1 billion cash deal tumblr, wsj reports )   

and need save "titles" posts. mean, 6 posts created , each of them have 1 title array.

other things date, body, excerpt etc. default or null. change them later in admin if needed.

and set state draft instead of published.

what best practice how such task? creating own plugin , need advice how save multiple posts @ once in wordpress.

you may try this

global $user_id; // logged in user id $term = get_term_by('name', 'php', 'category'); // category name assumed 'php' $cat = $term->term_id; // id of php category $titles = array('post-one', 'post-two'); // titles array foreach($titles $title) {     $new_post = array(         'post_title' => $title,         'post_content' => 'lorem ipsum dolor sit amet...',         'post_status' => 'draft',         'post_date' => date('y-m-d h:i:s'),         'post_author' => $userid,         'post_type' => 'post',         'post_category' => array($cat)     );     wp_insert_post($new_post); // insert post     // or     $newpostid = wp_insert_post($new_post); //  new post id in $newpostid } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -