【发布时间】:2015-10-08 05:30:27
【问题描述】:
我正在使用 Wordpress 4.2.2,在带有 PHP 5.6.8 的 Windows 中安装 Xampp
我在我的主题的functions.php中添加了以下函数来自动设置帖子类型'departure'的标题:
function custom_title() {
if ($_POST['post_type'] == 'departure') :
$post_title = 'Departure-'.$_POST['post_ID'];
return $post_title;
endif;
}
add_filter ( 'title_save_pre', 'custom_title' );
自定义帖子类型“出发”的标题设置工作正常。但是当我尝试添加一个新的 wordpress 标准帖子(即 post_type = post)时,我收到以下错误:
警告:从 wp-admin\includes\post.php 第 627 行的空值创建默认对象
第627行如下:
/**
* Filter the default post content initially used in the "Write Post" form.
*
* @since 1.5.0
*
* @param string $post_content Default post content.
* @param WP_Post $post Post object.
*/
$post->post_content = apply_filters( 'default_content', $post_content, $post );
所有其他帖子类型(即自定义类型和 wordpress 标准页面)都可以正常工作。通过将 $_POST 数据转储到我所看到的日志文件中,对于所有工作后的类型,一个空数组(即 array())作为 $_POST 数据传递。 “帖子”帖子类型不会发生这种情况。
如果我在functions.php中注释该函数,则在添加新的“post”帖子类型时会发送一个空数组作为$_POST数据,问题就消失了。
有什么想法吗?
谢谢
【问题讨论】:
标签: wordpress wordpress-theming