post_status => publish not working

I have a front end form that let users submit a post. This is how i store the data when a post is submitted : if ( isset( $_POST[‘submitted’] )) { $post_information = array( ‘post_title’ => wp_strip_all_tags( $_POST[‘postTitle’] ), ‘post_content’ => $_POST[‘postContent’], ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’ ); $new_post = wp_insert_post( $post_information ); The … Read more

How to update post parent?

I have an array of image id’s and i want assign them to the specific post: foreach ($image_ids as $image_id) var_dump(wp_insert_post(array(‘ID’ => $image_id, ‘post_parent’ => $new_post_id), TRUE)); But there occurs error: object(WP_Error)#252 (2) { [“errors”]=> array(1) { [“empty_content”]=> array(1) { [0]=> string(38) “Content, title, and excerpt are empty.” } } [“error_data”]=> array(0) { } } … Read more

How to add multiple product gallery images from front-end

-I am running a woo commencers shop -Users have the ability to add products using wp insert post -The product gallery multiple image upload will only add the last image to the post but in media they are all attached to the correct post This is my code function.php function my_handle_attachment($file_handler,$post_id,$set_thu=false) { if ($_FILES[$file_handler][‘error’] !== … Read more

Prevent Duplicate Attachment When Using wp_insert_post

I am trying to use wp_insert_attachment while using wp_insert_post. It’s successfully creating the post and attachment. It have no problem if I only use the wp_insert_post function, but when I activating the wp_insert_attachemnt, the script create both, duplicate posts and attachments 3 times of the previous created posts and attachments. Here is the code (UPDATED): … Read more

How do I set a featured image (thumbnail) by image URL when using wp_insert_post()?

While looking through the function reference entry for wp_insert_post(), I noticed that there’s no parameter in the array it requires which will allow me to set the ‘Featured Image’ for a post, displayed as the post thumbnail in my theme. I have looked into functions like set_post_thumbnail(), as suggested by Mr. Bennett, but this seems … Read more

Is there a better way to programmatically insert content into a page?

During activation of the plugin I’m writing, I insert a custom page. I can add post_content using the wp_insert_post command, which seems like a reasonable way to add a limited amount of content. For example, something simple as part of an array could be: ‘post_content’='<h1> Header </h1>’ However, I would like to add a full … Read more