function cgp_create_post($title, $name){
$new_post = array(
'post_title' => $title,
'post_type' => 'custom-post-type',
'post_status' => 'publish'
);
$mypost_id = post_exists( $title );
if (!$mypost_id) {
$mypost_id = wp_insert_post( $new_post, true );
}
echo $mypost_id; //this was never echoed and the script abruptly stops here
update_post_meta( $mypost_id, 'times', '1' );
}上面是我的代码片段,结果是创建了定制的post,但是当我通过回显$mypost_id的值测试值时,它从来没有回显任何东西,脚本也突然停在了这一行。
发布于 2018-06-06 07:10:04
显然我上面的剧本没什么问题。实际上,与另一个插件存在冲突,该插件通过add_action(“保存_post”、“function_name”)两次调用同一个第三方脚本。这双触发第三方脚本,并导致错误,当我的脚本上面试图做插入帖子。
我打开了在wp-config.php上的调试,方法是:定义(‘WP_ debug’,true);定义(‘WP_DEBUG_LOG’,true);
然后通过提供的错误日志解决错误。
https://wordpress.stackexchange.com/questions/305404
复制相似问题