Works flawlessly now. Updated code. Thank you newfurniturey.
function foo_options(){
global $post;
if (isset($custom['website_url']) && isset($custom['website_url'][0])) {
$website_url = isset($custom['website_url']) ? $custom['website_url'][0] : '';}
?>
<div id="foo-options">
<label>Website URL:</label><input name="website_url" value="<?php echo $website_url; ?>" />
</div><!--end foo-options-->
<?php
}
{
function update_website_url(){
global $post;
if (($post != null) && isset($_POST['website_url'])) {
update_post_meta($post->ID, "website_url", $_POST["website_url"]);
}
}
Updated code and bin. http://pastebin.com/2ZWisprm
To address the issues in-order, regarding the following line:
trying to access a property of a non-objectapplies to$post->ID. The only way this error can occur is if$postis not an object (such as an array), or if it’snull.The
undefined indexerror applies to$_POST["website_url"]; This will happen when either your form is not currently being POSTed, or the field-name does not exist in the current POST data.I do not know what object is supposed to be within your
$postvariable, so the following is just a guess, but try the following update:This will make sure
$postis not null, and by assumption that it is a proper object, and that thewebsite_urlindex has been set. You may want to increase the check to use!empty()instead ofisset(), but the above should resolve your error (unless$postis an array, or other non-object data type).