0

今は完璧に動作します。更新されたコード。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"]);
     }
  }

コードとビンを更新しました。http://pastebin.com/2ZWisprm

4

1 に答える 1

1

次の行に関して、問題に順番に対処するには:

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

trying to access a property of a non-objectに適用され$post->IDます。このエラーが発生する唯一の方法は$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"]);
    }
}

これにより、null ではないことが確認され、それが適切なオブジェクトであり、インデックスが設定されている$postことが前提となります。の代わりにwebsite_urlチェックを増やして使用することもできますが、上記の方法でエラーを解決できます (が配列またはその他の非オブジェクト データ型でない限り)。!empty()isset()$post

于 2012-08-29T21:07:47.733 に答える