2013-06-17 6 views
0

등록 된 메타 박스를 다른 메타 박스 나 택 소노 미 필드에서 선택/입력 한 것을 기반으로 여러 번 동적으로 나타낼 수있는 방법이 있습니까?메타 폼을 "즉시"워드 프레스 게시

즉, 내 맞춤 게시물은 다양한 양의 "섹션"(텍스트 필드)을 가져야합니다. 얼마나 많은 것을 미리 정의 할 수있는 방법이 없을 것입니다. 데이터 입력 중에 만 해당 금액을 알 수 있습니다. 이 필드는 표시되는 게시 템플리트에 동적으로 추가됩니다.

답변

0

내 사용자 지정 사후라는 포스트 및 콜백 "display_post_meta_box"와 METABOX를 등록하면이 일 :

function display_post_meta_box($post) { 

     // Retrieve current details of the post based on post ID  
    $section_number = get_post_meta($post->ID, 'section_number', true) ; 
    /*Configuration for post section WYSIWYG editors*/ 
       $i = 1; 
       while ($i <= $section_number) { 
    $section_editor_settings[$i] = array( 'textarea_rows' => '5','media_buttons' => false, 'textarea_name'=>__('post_section'.$i), 'teeny'=>'true'); 
    $i++; } 



     // Retrieve current details of the post based on post ID 
    $section = get_post_meta($post->ID, 'section', true); 
    $section_number = get_post_meta($post->ID, 'section_number', true) ;   

    ?> 
     <style>.cell{display: table-cell; vertical-align: middle;} 
    .row{width: 100%;display: table;border-bottom: 1px solid #DFDFDF;padding: 2px;} 
    </style> 



     <div class="row"> 
            <div class="cell" style="width: 15%"><b>Number of sections</b></div> 
            <div class="cell" style="width: 10%"><input type="number" name="post_section_number" value="<?php echo $section_number; ?>" /></input></div> 
            <div class="cell" style="width: 5%">  <script> 
     jQuery('.metabox_submit').click(function(e) { 
      e.preventDefault(); 
      jQuery('#publish').click(); 
     }); 
     </script> 
     <input type="submit" class="metabox_submit button button-primary" value="Submit" /></div> 
            <div class="cell" style="width: 70 %"> &nbsp;</div> 
            </div> 


    <?php 
       $i = 1; 
       while ($i <= $section_number) {?> 
         <div class="row"> 
            <div class="cell" style="width: 30%"><b>Section <?php echo '#'.$i;?> </b></div> 
            <div class="cell" style="width: 50%"><?php wp_editor($section[$i], 'sectionid'.$i, $section_editor_settings[$i] ); ?> </div> 
            <div class="cell" style="width: 5%"></div> 
            <div class="cell" style="width: 15%"><p class="howto">Enter body for this section here, and apply neccessary formatting</p></div> 
            </div> 
    <?php $i++; } 

} 

/포스트/

add_action('save_post', 'add_post_fields', 10, 2); 

function add_post_fields($post_id, $post) { 
    // Check post type for movie reviews 
    $section_values[] = array(); 

    if ($post->post_type == 'post') { 
     $i = 1; 
       while ($i <= 4) { 

        $section_values[$i] = $_POST['post_section'.$i]; 

        $i++; } 
     // Store data in post meta table if present in post data 
     if (isset($section_values) && $section_values != '') { 
      update_post_meta($post_id, 'section', $section_values); 
     } 

      if (isset($_POST['post_section_number']) && $_POST['post_section_number'] != '') { 
      update_post_meta($post_id, 'section_number', $_POST['post_section_number']); 
     } 

    } 
} 
저장
0

위를 할 특정 코드를 요청하는 경우 나도 몰라,하지만 일반적인 질문의 그것의 더 있다면 그것은 기능의 하중을 가지고 Types plugin

를 추천 할 것입니다,하지만 당신이 선택할 수 있습니다 어떤 사용자 정의 필드의 게시물 유형 그룹이 표시되는지, 어떤 페이지 템플릿이 표시되는지, 중요한 것은 질문에 대해 다른 필드 값을 기반으로하는 조건부 표시도 있습니다. 약간 더 구체적인 질문이없이 이것이 얼마나 유용할지 모르겠다. 코드 미답이 아니라 미안하다.하지만 도움이 되길 바란다.

관련 문제