2014-09-04 2 views
0

메타 게시물을 내 게시물 페이지에 추가 했으므로 각 게시물의 레이아웃을 선택할 수 있습니다. 메타 상자를 만들었지 만 표시되지만 저장되지는 ​​않습니다.Wordpress 게시물 레이아웃 메타 박스가 저장되지 않습니다.

if (! function_exists('post_layout_meta_box')){ 
    function post_layout_meta_box($post){ 
     $custom = get_post_custom($post->ID); 
     $page_layout = isset($custom["page_layout_left"][0]) ? $custom["page_layout_left"][0] : (isset($custom["page_layout_right"][0]) ? $custom["page_layout_right"][0] : $custom["page_layout_none"][0]); 
     ?> 
     <p> 
      <select name="page_layout" id="page_layout"> 
       <option value="left_sidebar" <?php selected($page_layout, 'left_sidebar'); ?>>Left Sidebar</option> 
       <option value="right_sidebar" <?php selected($page_layout, 'right_sidebar'); ?>>Right Sidebar</option> 
       <option value="full_width" <?php selected($page_layout, 'full_width'); ?>>No Sidebar</option> 
      </select> 
     </p> 
     <?php 
    } 
} 


if (! function_exists('post_save_layout_meta_box')){ 
    function post_save_layout_meta_box($post_id){ 

     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ 
      return $post_id; 
     } else{ 
      if(isset($_POST['page_layout'])) { 
       update_post_meta($post_id, 'page_layout', wp_kses($_POST['page_layout'], '')); 
      } 
     } 
    } 
} 

add_action('save_post', 'post_save_layout_meta_box'); 

그래서 나는 무엇이 누락 되었습니까? 예를 들어 오른쪽 사이드 바를 선택하면 페이지를 업데이트 한 후 값을 왼쪽 사이드 바에 반환합니다.

편집 : 그것을 알아 냈 :

문제는이에 있었다가 :

$page_layout = isset($custom["page_layout_left"][0]) ? $custom["page_layout_left"][0] : (isset($custom["page_layout_right"][0]) ? $custom["page_layout_right"][0] : $custom["page_layout_none"][0]); 

그것은 코드 줄에 문제가

나는이 추측
$page_layout = isset($custom["page_layout"][0]) ? $custom["page_layout"][0] : 'left_sidebar'; 

답변

0

이 있어야한다. Wordpress는 page_layout_left, page_layout_right와 혼동합니다. 당신은 당신이 먼저 즉 왼쪽이나 오른쪽으로 또는 전체 폭 선택한 항목 옵션을 사용자 찾아야한다 update_post_meta에서() 함수를 page_layout_left을 사용하려면

$page_layout = isset($custom["page_layout_left"][0]) ? $custom["page_layout_left"][0] : (isset($custom["page_layout_right"][0]) ? $custom["page_layout_right"][0] : $custom["page_layout_none"][0]); 

update_post_meta($post_id, 'page_layout', wp_kses($_POST['page_layout'], '')); 

나는 제안한다.

그런 다음 page_layout 사용자 정의 필드 이름 대신 update_post_meta 함수에서 page_layout_left 또는 page_layout_right를 사용하십시오.

update_post_meta($post_id, 'page_layout_left', wp_kses($_POST['page_layout'], '')); 

희망 일 수 있습니다.

해피 코딩.

아툴 진달

+0

네가 옳았 어, 내 if 절이 틀렸어. 알아 냈어. 그것을 지적 주셔서 감사합니다. –

관련 문제