2017-02-23 5 views
0

나는 현재 WordPress의 플러그인을 만드는 방법 자습서를하고 있어요하지만 어떤 이유로 내 코드는 포스트 메타 데이터가 데이터베이스에 저장되는 부분에 관해서는 작동하지 않습니다 . 게시 또는 업데이트를 클릭하면 페이지가 새로 고쳐지고 필드의 내용이 사라집니다. 이 자습서는 2015 년에 만들어졌으며 코드에 누락 된 부분이 있는지 또는 WordPress에서 데이터를 저장하는 방법이 변경되었는지 여부는 잘 모르겠습니다. 여기 튜토리얼 특정 동영상에 링크입니다 - 여기 https://www.youtube.com/watch?v=waS0gCkuLeM&t=64s&index=10&list=PLIjMj0-5C8TI7Jwell1rTvv5XXyrbKDcy저장 워드 프레스 포스트 메타 작동하지 않는 데이터베이스에

그리고 아래 그 튜토리얼 내 코드입니다 :

<?php 

function fd_add_custom_metabox(){ 

add_meta_box(

     'fd_meta', 
     'Pricing Table', 
     'fd_meta_callback', 
     'table', 
     'normal', 
     'core' 

     );} 

add_action('add_meta_boxes', 'fd_add_custom_metabox'); 

function fd_meta_callback($post){ //needed for the $callback parameter above 
    wp_nonce_field(basename(__FILE__), 'fd_table_nonce'); 
    $fd_stored_meta = get_post_meta($post->ID); 


    ?> 

<div> 
    <div class="meta-row"> 
     <div class="meta-th"> 
      <label for="table-title" class="fd-row-title">Title</label> 
     </div> 
     <div class="meta-td"> 
      <input type="text" name="table_id" id="table-title" value="<?php if(!empty ($fd_stored_meta['table_id'])) {echo esc_attr($fd_stored_meta['table_id'][0]); } ?> "> 
     </div> 
    </div> 
</div> 
<div> 
    <div class="meta-row"> 
     <div class="meta-th"> 
      <label for="table-subtitle" class="fd-row-title">Subtitle</label> 
     </div> 
     <div class="meta-td"> 
      <input type="text" name="table_subtitle" id="table-subtitle" value="<?php if(!empty ($fd_stored_meta['table_subtitle'])) {echo esc_attr($fd_stored_meta['table_subtitle'][0]);} ?> "> 
     </div> 
    </div> 
</div> 
<div> 
    <div class="meta-row"> 
     <div class="meta-th"> 
      <label for="table-recurrence" class="fd-row-title">Recurrence</label> 
     </div> 
     <div class="meta-td"> 
      <input type="text" name="table_recurrence" id="table-recurrence" value=""> 
     </div> 
    </div> 
</div> 
<div> 
    <div class="meta-row"> 
     <div class="meta-th"> 
      <label for="table-price" class="fd-row-title">Price</label> 
     </div> 
     <div class="meta-td"> 
      <input type="text" name="table_price" id="table-price" value=""> 
     </div> 
    </div> 
</div> 
<div> 
    <div class="meta-row"> 
     <div class="meta-th"> 
      <span>Features</span> 
     </div> 
     <div class="meta-td"> 

      <textarea name="table_features" rows="8" cols="50"></textarea> 
     </div> 
    </div> 
</div> 
<div class="meta"> 
    <div class="meta-th"> 
     <span>Some Description</span> 
    </div> 
</div> 
<div class="meta-editor"> 
<?php 

    $content = get_post_meta($post->ID, 'some_description', true); 
    $editor = 'some_description'; 
    $settings = array(
    'textarea_rows' => 8, 
    'media_buttons' => true, 

    ); 

    wp_editor($content, $editor, $settings); 
?> 
    </div> 

<?php 


} 

function fd_meta_save($post_id){ 
    //checks save status 
    $is_autosave = wp_is_post_autosave($post_id); 
    $is_revision = wp_is_post_revision($post_id); 
    $is_valid_nonce = (isset($_POST[ 'fd_table_nonce']) && wp_verify_nonce($_POST['fd_table_nonce'], basename(__FILE__)))? 'true' : 'false'; 

    //Exits script depending on save status 
    if ($is_autosave || $is_revision || !$is_valid_nonce){ 
     return; 
    } 

    if (isset ($_POST['table_id'])){ 
     update_post_meta($post_id, 'table_id', sanitize_text_field($_POST[ 'table_id' ])); 
    } 
    if (isset ($_POST['table_subtitle'])){ 
     update_post_meta($post_id, 'table_subtitle', sanitize_text_field($_POST[ 'table_subtitle' ])); 
    } 
    if (isset ($_POST['some_description'])){ 
     update_post_meta($post_id, 'some_description', sanitize_text_field($_POST[ 'some_description' ])); 
    } 
} 
add_action('save_post,', 'fd_meta_save'); 

나는 데이터 만 캡처 처음 두 입력에 PHP를 가지고 있습니다 및

내가 잘못 또는 무엇 지난 2 년 동안 변경된 경우 나에게 보여 도와주세요 마지막 인 WP-편집기.

+0

모든 라이브 링크 ?? –

+0

print_r을 사용하여 $ fd_stored_meta를 인쇄하고 그 값의 출현 여부를 확인할 수있는 코드를 작성해 주시겠습니까? 이 후 $ fd_stored_meta = get_post_meta ($ post-> ID); – Tristup

+0

@Umair 어떻게이 코드를 실시간으로 공유 할 수 있습니까? Codepen과 JSfiddle에 대해서만 알고 있지만 PHP는 지원하지 않습니다. 알려주세요. – Feyt

답변

0

이 질문에 업데이트. 내가 바로 포스트 후 매우 끝에 쉼표을 한 것으로 나타납니다 - 그래서이 ADD_ACTION ('save_post', 'fd_meta_save')과 같이한다; 대신 add_action ('save_post,', 'fd_meta_save');

내 문제를 해결했습니다. 문자열로 읽었 기 때문에 구문 오류로 인식 할 수 없습니다.

학습 된 내용 - 프로그램에서 오류를 찾지 않아도 구문 오류를 찾지 마십시오.

관련 문제