wordpress custom post type error when post

I have 2 custom post types in WordPress: ‘homepage’ and ‘story’ and I have installed a plugin ‘Post from Site’. When I try to post into ‘story’ from front page with this plugin i get a few errors.

You can try too here: http://www.teenbetween.relationshipsireland.com/your-family-life/accepting-the-decision/ – you will find below image a link, use it.

Read More

And the article is posted but i get the error.

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}

This is story.php 45:

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

and 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
}

Any help please?

Related posts

Leave a Reply

1 comment

  1. The $post object isn’t available during the save_details function. When you call the function, pass in the $post_id as the first parameter. You’ll also want to move the authorization code in story.php into the save_details function.

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

    See this for reference: http://codex.wordpress.org/Plugin_API/Action_Reference/save_post

    If that doesn’t work you can try http://wordpress.org/extend/plugins/advanced-custom-fields/