Php 未定义索引:网站url和自定义url$POST

Php 未定义索引:网站url和自定义url$POST,php,Php,现在工作完美无瑕。更新代码。谢谢你,新家具 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] : '';} ?>

现在工作完美无瑕。更新代码。谢谢你,新家具

  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"]);
     }
  }
函数foo_options(){
全球$员额;
if(isset($custom['website\u url'])和&isset($custom['website\u url'][0])){
$website\u url=isset($custom['website\u url'])?$custom['website\u url'][0]:“”;}
?>

网站URL:按顺序解决以下问题:

update_post_meta($post->ID, "website_url", $_POST["website_url"]);
尝试访问非对象的属性
适用于
$post->ID
。发生此错误的唯一方法是
$post
不是对象(如数组),或者
为null

未定义索引
错误适用于
$\u POST[“网站url”]
;当您的表单当前未发布,或者当前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
不为空,前提是它是一个正确的对象,并且
网站url
索引已设置。您可能希望增加检查以使用
!empty()
而不是
isset()
,但上述操作应该可以解决您的错误(除非
$post
是数组或其他非对象数据类型).

你的意思是要引用超级全球
$\u POST
而不是
$POST
?是的,我想我的问题对于熟练的程序员来说非常微不足道,真的很抱歉,并将使用你的链接作为参考,但是这个答案很准确,并且减轻了2天的搜索时间。新家具-谢谢。工作很好,但现在正在发布未定义索引:第4行的网站url。我尝试了您以前的代码,但它给出了错误消息,并将错误代码放入url输入框中。这就像鼹鼠摇摇晃晃地跳出来一样,我无法赢得呵呵。我以前的回答在技术上应该适用于您的第4行;使用
isset($custom['website\u url'])
将解决
未定义索引
错误。如果您从未声明
$website\u url
,根据
isset()
返回false,您的
将抛出一个关于
未定义变量$website\u url的新错误;
尝试,而不是以前的答案:
$website\u url=isset($custom['website\u url')?$custom['website\u url'][0]:'';
更新到顶部。我也只是想说声谢谢。我意识到帮助像我这样的新手需要宝贵的时间,我真的很感激。虽然我有过isset检查的经验,但我还不能掌握如何使用$POST实现它。再次感谢。