Could not get post ID from wp_insert_post()

Apparently there is nothing wrong with my script above. There is actually a conflict with another plugin which called the same 3rd party script twice via add_action( ‘save_post’, ‘function_name’). This double fired the 3rd party script and caused error when my script above try to do insert post. I have turned on debug at wp-config.php … Read more

wp_insert_post not working

I guess the reason is you have not added post title and added post id $my_post = array( ‘post_id’ => 1, ‘post_status’ => ‘pending’, ‘post_type’ => ‘post’ ); Ideally if should be $my_post = array( ‘post_title’ => wp_strip_all_tags( $_POST[‘post_title’] ), ‘post_content’ => $_POST[‘post_content’], ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_category’ => array( 8,39 ), ‘post_type’ … Read more

How Can I Set the Post Author of a Post I Just Created With PHP?

If you know the ID of the author you can use wp_insert_post specifying the ID and the author ID to it. $id = $post->ID; // change this to whathever $user_id = ‘4’; // change this too $the_post = array(); $the_post[‘ID’] = $id; $the_post[‘post_author’] = $user_id; wp_insert_post( $the_post ); The trick is to specify the ID … Read more

WP Cron is “half-failing” to insert posts

I just encountered this very same problem. I was trying to do wp_insert_post() from within a cron action, and the script would apparently just die during some save_post action handler. I tracked down my problem, which turned out to be a save_post handler which is used to save the POST data from a custom metabox. … Read more

HTML Entities in Post Title

It seems like the crux of the question is this: This causes the first ‘if’ condition to return TRUE and it inserts a duplicate post. Check for the post_name instead. That value is normalized to lowercase and dashes by sanitize_title_with_dashes so you won’t have this issue. That value is also the one that WordPress enforces … Read more

after wp_insert_post need to get the post id

$post_ID = wp_insert_post($post); … should work, as you mentioned. From the Codex: Returns the ID of the post if the post is successfully added to the database. On failure, it returns 0 if $wp_error is set to false, or a WP_Error object if $wp_error is set to true.

wp_insert_post -> post_content not showing

OK, SO this is what I found out, the data <object>…</object> was the culprit. WordPress sanitizes the input before committing to the database. Other non allowed tags include <embed>…</embed> I’ve seen this solution online $postData = array( … ‘filter’=>true … ); However, some people say that’s a security flaw. I dug a little deeper and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)