wp_insert_post incorrectly escapes HTML comments when they include tags

The following program: <?php $_SERVER[‘HTTP_HOST’] = ‘localhost’; require_once(‘wp-load.php’); $post = array( ‘post_title’ => ‘HTML Escape’, ‘post_content’ => ‘This is <!– a comment –><br/>This is <!– <p>a comment</p> –>’, ‘post_status’ => ‘publish’ ); $id = wp_insert_post($post); $post = get_post($id); var_export( esc_html( $post->post_content ) ); ?> Outputs the following in the browser: ‘This is <!– a comment … Read more

WP insert post and custom taxonomy

Where is the code that catches an processes the $_POST data? Is it in a template file? Or is it in a function that is run on a hook? If it’s the latter, and if taxonomy_exists() is returning false as you suggest here (http://wordpress.stackexchange.com/questions/45798/wp-insert-post-and-custom-taxonomy#comment58402_45810), it’s possible that you’re checking before register_taxonomy has had a chance … Read more

can’t edit post_modified in wp_insert_post (bug?)

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’ == … Read more

Create posts on user registration

You kind of answered the question yourself already, Create a function that will create the 3 posts ex: function create_new_user_posts($user_id){ if (!$user_id>0) return; //here we know the user has been created so to create //3 posts we call wp_insert_post 3 times. // Create post object $my_bio_post = array( ‘post_title’ => ‘bio’, ‘post_content’ => ‘This is … Read more

Get post ID from wp_insert_post()

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 = wp_insert_post($new_post); ?> <form method=”post” action=”your-action.php”> … Read more

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