发帖时wordpress自定义帖子类型错误

时间:2013-01-29 15:03:41

标签: wordpress custom-post-type

我在Wordpress中有2个自定义帖子类型:'主页'和'故事',我已经安装了一个插件'来自网站的帖子'。当我尝试使用此插件从首页发布到“故事”时,我会收到一些错误。

你可以在这里试试:http://www.teenbetween.relationshipsireland.com/your-family-life/accepting-the-decision/ - 你会在下面找到一个链接,使用它。

文章已发布,但我收到错误。

Notice: Trying to get property of non-object in teenbetween.relationshipsireland.com/wp-content/themes/teenbetween/includes/homepage.php on line 79 
Notice: Undefined index: link_homepage in teenbetween.relationshipsireland.com/wp-content/themes/teenbetween/includes/homepage.php on line 79 
Notice: Trying to get property of non-object in teenbetween.relationshipsireland.com/wp-content/themes/teenbetween/includes/story.php on line 45 
Notice: Trying to get property of non-object in teenbetween.relationshipsireland.com/wp-includes/capabilities.php on line 1069 
Notice: Trying to get property of non-object in teenbetween.relationshipsireland.com/wp-includes/capabilities.php on line 1073 
Notice: Trying to get property of non-object in teenbetween.relationshipsireland.com/wp-includes/capabilities.php on line 1075 
Notice: Trying to get property of non-object in teenbetween.relationshipsireland.com/wp-includes/capabilities.php on line 1076 
Notice: Trying to get property of non-object in teenbetween.relationshipsireland.com/wp-includes/capabilities.php on line 1079 
Notice: Trying to get property of non-object in teenbetween.relationshipsireland.com/wp-content/themes/teenbetween/includes/story.php on line 46 {"image":"none","error":"","success":"Post added, please wait to return to the previous page.","post":1139}

这是story.php 45:

if ( !current_user_can( 'edit_post', $post->ID )){
    return $post->ID;
}

和homepage.php 79:

add_action('save_post', 'save_details');
function save_details(){ 
global $post;   
update_post_meta($post->ID, "link_homepage", $_POST["link_homepage"]);  // homepage.php 79
}

请帮忙吗?

1 个答案:

答案 0 :(得分:3)

$post功能期间save_details对象不可用。调用该函数时,将$post_id作为第一个参数传入。您还需要将story.php中的授权码移动到save_details功能。

function save_details($post_id){ 
    update_post_meta($post_id, "link_homepage", $_POST["link_homepage"]);  // homepage.php 79
}

请参阅此参考:http://codex.wordpress.org/Plugin_API/Action_Reference/save_post

如果这不起作用,您可以尝试http://wordpress.org/extend/plugins/advanced-custom-fields/

相关问题