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

标签 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
}

请问有什么帮助吗?

最佳答案

$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/

关于wordpress 自定义帖子类型发帖时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14585912/

相关文章:

wordpress - 定义了特定 post_type 的帖子内的页面导航在 Wordpress 中不起作用

mysql - 使用 SQL 命令从服务器上所有数据库的表中获取列值?

php - 在 2 个 WordPress 上共享用户安装在同一服务器上的 2 个子域中

css - 如何在自定义 css 框 wordpress 中隐藏主题功能

wordpress - 如何根据语言重写自定义帖子类型 slug?

wordpress - 帖子类型分层

javascript - 在 jQuery 中移动 DOM 元素(图层 slider )

javascript - 重力形式从下拉选择中显示消息

wordpress - 如何从前端保存带有元框的自定义帖子类型

wordpress - 您可以将自定义帖子类型帖子设置为 WordPress 中的静态主页吗?