New answers tagged

0

I've actually forgotten to create the function for uploading and attaching images. I've found the correct method into another question here Uploading Multiple Attachments From Front-End With A Description.


1

You'll have to do this in two steps. First, you will create a post in the draft mode, using wp_insert_post(). The wp_insert_post itself will return to you the ID of the inserted post: <?php $new_post = array( 'post_title' => 'Draft title', 'post_status' => 'draft' 'post_type' => 'my_custom_type' ); $postId = ...


1

Check the documentation: Return: (int|WP_Error) The post ID on success. The value 0 or WP_Error on failure. Thus: $result = wp_insert_post( $data ); if ( $result && ! is_wp_error( $result ) ) { $post_id = $result; // Do something else }


3

It is not bug, actually WordPress does not allow (using arguments) to set post modification date. Internally WordPress set it to current time if you are updating an existing post else just set it to post date. in /wp-includes/post.php#L3192 you can see wp_insert_post does not use this argument if ( $update || '0000-00-00 00:00:00' == $post_date ) { ...


0

I played around with the plugin files and was able to figure it out myself. For anyone who's wondering, you can use wp_insert_post. You just need to find what variable the generated shortcode is stored in, which can take a little digging through the plugin files. For the plugin I was working with, it went something like this: $my_poll = array( ...


0

Today, I was trying to insert an imported data into WordPress. I was using wp_insert_post to insert data, and it threw the following error: WP_Error Object ( [errors] => Array ( [db_update_error] => Array ( [0] => Could not update post in the database ) ) [error_data] => Array ...



Top 50 recent answers are included