Wordpress和wp_insert_post不起作用

时间:2013-11-13 17:28:56

标签: php wordpress

我正在使用与wordpress网站配合使用的网络应用程序。

直到昨天所有的作品都像魅力一样,但从今天起,当我在wordpress db上保存帖子时,它现在无法正常工作...... 不给我错误(php错误或wordpress错误),而只是一个白页。

这是我的完整代码:(很抱歉许多评论行和回声,但我正在测试)

重要的部分:

  // Create post object
  $my_post = array(
    'post_title'    => $article_title,
    'post_name'   => $article_title,
    'post_content'  => $article_content,
    'post_status'   => 'pending',
    'post_author'   => 1
  );

  // Insert the post into the database
  wp_insert_post($my_post, TRUE);// try first time

  $post_status = "pending";
  $post_type = "post";
  $post_parent = "0";

  $post_ID = (int) $wpdb->insert_id;
  echo $post_ID; die;

昨天有一个简单的wp_insert_post(my_post);一切正常,今天(当然我认为我编辑了一些文件......或者我现在没有),不是更多的工作而不是给我错误。

您怎么看?

谢谢,真的!

编辑:问题是我没有插入post_category而wp需要它!

1 个答案:

答案 0 :(得分:0)

您可以使用wp_insert_post()函数捕获$ post_id ...

$post_ID = wp_insert_post($my_post, TRUE);// try first time

然后你可以转出$ post_ID变量来获取ID或错误。

var_dump($post_ID);