2016-01-27 25 views
0

我正在爲我的一個項目構建一個自定義插件,我正面臨着我創建的自定義字段的這個問題,但是一旦我嘗試保存字段。我沒有收到管理編輯器中顯示的數據。 screenshot of issue pageWordpress發佈沒有在編輯器中更新

我在下面添加代碼請找到它。

<?php 

function apt_add_fields_metabox() 
{ 
    add_meta_box(
     'apt_college_fields', 
     __('College Fields'), 
     'apt_college_fields_callback', 
     'college', 
     'normal', 
     'default' 
    ); 
} 

add_action('add_meta_boxes','apt_add_fields_metabox'); 

//Display Fields Metabox Content 

function apt_college_fields_callback($post) 
{ 
    wp_nonce_field(basename(__FILE__),'wp_college_nonce'); 
    $apt_college_stored_meta = get_post_meta($post->ID); 
    ?> 
    <div class="wrap college-form"> 
     <div class="form-group">  
      <label for="issue_check"><?php esc_html_e('Issue Date Available','apt_domain'); ?></label> 
      <select name="issue_check" id="issue_check"> 
       <?php 
        $option_value = array('Yes','No'); 
        foreach($option_value as $key => $value) 
         { 
          if($value == $apt_college_stored_meta['issue_check'][0]) 
           { ?> 
            <option selected><?php echo $value; ?></option>          
          <?php 
           } 
          else 
           { 
          ?> 
           <option ><?php echo $value; ?></option> 
          <?php 

           } 
         } 
       ?> 
      </select> 
     </div> 

     <div class="form-group"> 
      <label for="college-details"><?php esc_html_e('College Details','apt_domain'); ?></label> 
      <?php 
       $content = get_post_meta($post->ID,'college-details',true); 
       $editor = 'college-details'; 
       $settings = array(
         'textarea_rows' => 5, 
         'media_buttons' => true 
        ); 

       wp_editor($content,$editor,$settings); 
      ?> 
     </div> 
     <div class="form-group"> 
     <label for="application_date"><?php esc_html_e('Application Available Date','apt_domain'); ?></label> 
     <input type="date" name="application_date" id="application_date" value="<?php if(!empty($apt_college_stored_meta['application_date'])) echo esc_attr($apt_college_stored_meta['application_date'][0]); ?>" /> 
     </div> 
    </div> 
    <?php 
} 

function apt_college_save($post_id) 
    { 
     $is_autosave = wp_is_post_autosave($post_id); 
     $is_revision = wp_is_post_revision($post_id); 
     if(isset($_REQUEST['wp_college_nonce']) && wp_verify_nonce($_REQUEST['wp_college_nonce'],basename(__FILE__))) 
      { 
       $is_valid_nonce = true; 
      } 
     else 
      { 
       $is_valid_nonce = false; 
      } 

     if($is_autosave || $is_revision || !$is_valid_nonce) 
      {     
       return; 
      } 

     if(isset($_REQUEST['issue_check'])) 
      { 
       update_post_meta($post_id,'issue_check',sanitize_text_field(['issue_check'])); 
      } 

     if(isset($_REQUEST['college-details'])) 
      { 
       update_post_meta($post_id,'college-details',sanitize_text_field(['college-details'])); 
      } 

     if(isset($_REQUEST['application_date'])) 
      { 
       update_post_meta($post_id,'application_date',sanitize_text_field(['application_date'])); 
      }   
    } 

add_action('save_post','apt_college_save'); 
?> 
+0

之前發佈,請檢查如果問題的預覽看起來不錯,或者如果您需要將代碼格式應用於代碼,它會讓您更容易理解您的問題他是觀衆。 – SaschaM78

+0

好的生病請確認下次格式化...謝謝 –

回答

1

沒有您的代碼block.you錯誤錯過了$ _REQUEST [ 'issue_check']

update_post_meta($post_id,'issue_check',sanitize_text_field(['issue_check']));

更正後的代碼

update_post_meta($post_id,'issue_check',sanitize_text_field($_REQUEST['issue_check']));

+0

謝謝你這麼多... –

相關問題