• Resolved juicetin

    (@juicetin)


    Hi I am actually trying to modify the TDO-Miniforms which uses wp_insert_post() to add a post.

    I am trying to make the form to post to the specific category on the page.

    I extract the category by reading the querystring. I have checked that the string value of the category is correctly extracted. However, after using wp_insert_post(), the post is being posted to the default category set in wp admin. Can anyone identify the problem? I suspect the wp_insert_post() has changed the category to the default that was set. Does the $post_category attribute in wp_insert_post() function reads this value correctly?

    How can I correct this problem?

    Thank you for anyone trying to help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter juicetin

    (@juicetin)

    Anyone has any idea how I can go about this? Is it because the variable that is accepted for the value of the category is an array instead of a nominal value?

    Thread Starter juicetin

    (@juicetin)

    Looks like I am replying all my own post. Ok, so when passing in the value of the specific category, in the wp_insert_post() function, it has to be an array!

    Juicetin, I would appreciate it if I could see the exact code for this, I’ve tried as in the example and it always posts to uncategorized.

    Thanks

    paranabis

    (@paranabis)

    Try This i think..

    //	 Finally; Post Into The Database
    function wp_ai_post($title, $content, $timestamp = null, $category = null, $status = 'draft', $authorid = null, $allowpings = true, $allowcomments = true )
    {
    	global $wpdb;
    	$date = ($timestamp) ? gmdate('Y-m-d H:i:s', $timestamp) : null;
    
    	   $postid = wp_insert_post(array(
    			'post_title'						=> $title,
    			'post_content'					=> $content,
    			'post_content_filtered'		=> $content,
    			'post_category'				=> $category,
    			'post_status'					=> $status,
    			'post_author'					=> $authorid,
    			'post_date'						=> $date,
    			'comment_status'				=> $allowcomments,
    			'ping_status'					=> $allowpings
    		));
    
    	do_action('publish_post', $postid);
    	return $postid;
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_insert_post() : I can’t get the post to the correct category’ is closed to new replies.