wp_insert post doesn't work

时间:2017-02-22 作者:Afaf

这是我的剧本:

$my_post = array(
                \'post_title\' => "post test",
                \'post_date\' => current_time(\'mysql\'),
                \'post_content\' => \'This is my post.\',
                \'post_status\' => \'publish\', 
                \'post_author\'   => 1,
                \'post_category\' => array(1)

            ); 
        $post_id= wp_insert_post($my_post);
        var_dump($post_id);

2 个回复
SO网友:bueltge

删除日期参数或对时间戳使用正确的格式,如date(\'Y-m-d H:i:s\'), 但这不是必需的,WP在插入post时间上使用当前时间戳。

SO网友:Esar-ul-haq Qasmi

日期参数错误。日期的格式应符合该职位的wp标准。下面的代码片段工作正常。

$my_post = array(
                \'post_title\' => "post test",
                \'post_date\' =>date(\'Y-m-d H:i:s\'),
                \'post_content\' => \'This is my post.\',
                \'post_status\' => \'publish\', 
                \'post_author\'   => 1,
                \'post_category\' => array(1)

            ); 
        $post_id= wp_insert_post($my_post); 
        var_dump($post_id);

相关推荐