Wordpress 和 wp_insert_post 不起作用 [英] Wordpress and wp_insert_post not working

查看:25
本文介绍了Wordpress 和 wp_insert_post 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个与 wordpress 网站配合使用的网络应用程序.

i'm doing an webapp that works with a wordpress website.

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

Until yesterday all works like a charm, but from today, when i save the post on wordpress db, it now not working... Not give me error (php error or wordpress error), but simply a white page.

这是我的完整代码:(对不起,很多注释行和回声,但我正在测试)

This is my full code:(sorry for many commented lines and echo, but i'm testing)

重要部分:

  // 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);一切正常,今天(当然我认为我编辑了一些文件......或者我现在没有),但工作不正常,也没有给我错误.

Yesterday with a simple wp_insert_post(my_post); all worked fine, today (of course i think i edited some files...or i don't now), not works more and not give me error.

你怎么看?

真的谢谢你!

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

推荐答案

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

You can capture the $post_id with the wp_insert_post() function...

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

然后您可以转储 $post_ID 变量以获取 ID 或错误.

Then you can dump out the $post_ID variable to get the ID or the error.

var_dump($post_ID);

这篇关于Wordpress 和 wp_insert_post 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆