未定义的索引:website_url和自定义url$POST


Undefined Index : website_url and custom url $POST

现在工作完美。已更新代码。谢谢你的新家具。

  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"]);
     }
  }

更新了代码和bin。http://pastebin.com/2ZWisprm

为了按顺序解决问题,关于以下行:

update_post_meta($post->ID, "website_url", $_POST["website_url"]);

CCD_ 1适用于CCD_。发生此错误的唯一方法是如果$post不是对象(例如数组),或者是null

undefined index错误适用于$_POST["website_url"];当您的表单当前未被POST,或者字段名称在当前POST数据中不存在时,就会发生这种情况。

我不知道$post变量中应该有什么对象,所以以下只是猜测,但请尝试以下更新:

function update_website_url(){
    global $post;   
    if (($post != null) && isset($_POST['website_url'])) {
        update_post_meta($post->ID, "website_url", $_POST["website_url"]);
    }
}

这将确保$post不为空,并假设它是一个适当的对象,并且website_url索引已经设置。您可能希望增加检查以使用trying to access a property of a non-object0而不是isset(),但以上操作应该可以解决您的错误(除非$post是数组或其他非对象数据类型)。