• Resolved Ququ

    (@ququ)


    Hi this code works fine with me ecxept it post in the default category
    can any one solve my proplem please ?

    $post_title='test';
    $post_title=trim($post_title);
    $post_date='';
    $post_date_gmt='';
    $post_author=1;
    $post_status = 'publish';
    $post_category = '8';
    $post_content='test';
    $post_ID = wp_insert_post(array(
    
    'post_title' 	=> $post_title,
    'post_content' 	=> $post_content,
    'post_category' => $post_category,
    'post_status' 	=> $post_status,
    'post_author'   => $post_author,
    'post_date'     => $post_date,
    'post_date_gmt' => $post_date_gmt
    ));
Viewing 1 replies (of 1 total)
  • Thread Starter Ququ

    (@ququ)

    hmmmmmmm i solve it
    the category must be in array

    $post_ID = wp_insert_post(array(
    
    'post_title' 	=> $post_title,
    'post_content' 	=> $post_content,
    'post_category' => array($post_category),
    'post_status' 	=> $post_status,
    'post_author'   => $post_author,
    'post_date'     => $post_date,
    'post_date_gmt' => $post_date_gmt
    ));

Viewing 1 replies (of 1 total)

The topic ‘Add post in different category with wp_insert_post’ is closed to new replies.