2012-09-20 7 views
0

다음 코드에서 테마가 어떻게 구성되었는지 알아 내려고합니다. 맞춤 게시 유형의 상점이 생성되고 있음을 알 수 있습니다. 내가 혼란 스러워요 곳 .. 이해 비트뿐만 아니라 필드로 .... 생성되는 'clpr_store_phone'라고 할 수있을 것 같습니다 WordPress 테마 구성 방법 이해 - 이상한 사용자 정의 게시 필드

register_taxonomy(APP_TAX_STORE, 
     array('promo_code','sale_offers','in_store','coupon'), 
     array( 'hierarchical' => true, 
       'labels' => array(
         'name' => __('Stores', 'appthemes'), 
         'singular_name' => __('Store', 'appthemes'), 
         'search_items' => __('Search Stores', 'appthemes'), 
         'all_items' => __('All Stores', 'appthemes'), 
         'edit_item' => __('Edit Store', 'appthemes'), 
         'update_item' => __('Update Store', 'appthemes'), 
         'add_new_item' => __('Add New Store', 'appthemes'), 
         'add_or_remove_items' => __('Add or remove Stores', 'appthemes'), 
         'separate_items_with_commas' => __('Separate Stores with commas', 'appthemes'), 
         'choose_from_most_used' => __('Choose from the most common Stores', 'appthemes'), 
         'new_item_name' => __('New Store Name', 'appthemes') 
       ), 
       'show_ui' => true, 
       'query_var' => true, 
       'update_count_callback' => '_update_post_term_count', 
       'rewrite' => array('slug' => $store_tax_base_url, 'with_front' => false, 'hierarchical' => true), 
     ) 
); 

function clpr_edit_stores($tag, $taxonomy) { 
$the_store_phone = get_metadata($tag->taxonomy, $tag->term_id, 'clpr_store_phone', true); 
?> 

<tr class="form-field"> 
    <th scope="row" valign="top"><label for="clpr_phone"><?php _e('Phone Number', 'appthemes'); ?></label></th> 
    <td><input type="text" name="clpr_store_phone" id="clpr_store_phone" value="<?php echo $the_store_phone; ?>"/><br /></td> 
</tr> 

<?php 
} 
add_action('stores_edit_form_fields', 'clpr_edit_stores', 10, 2); 

function clpr_save_stores($term_id, $tt_id) { 
if (!$term_id) return; 

if(isset($_POST['clpr_store_phone'])) 
    update_metadata($_POST['taxonomy'], $term_id, 'clpr_store_phone',  $_POST['clpr_store_phone']); 
} 
add_action('edited_stores', 'clpr_save_stores', 10, 2); 

이것은 무엇 여기서 준비 중이 야? 'clpr_store_phone'은 분류 체계 내의 맞춤 입력란입니까?

누군가가 그것에 대해 밝힐 수 있습니까?

답변

2

게시 한 제한된 코드를 보면 분류 분류 유형에 대한 맞춤 메타 테이블이 생성 된 것으로 보입니다.

get_metadata 함수를 검색하면 캐시에서 메타 값을 가져 오려고 시도하고 거기에 없으면 update_meta_cache을 호출하여 메타 캐시를 준비합니다. update_meta_cache는 get_metadata에 전달 된 $meta_type 값에서 테이블 이름을 생성하는 _get_meta_table (아래 링크 참조) 기능을 사용합니다. 분류 유형이 존재하지 않기 때문에 사용자 정의 테이블을 만들고 테이블 이름을 추가해야합니다. 그것에 대해 $wpdb

function _get_meta_table($type) { 
    global $wpdb; 

    $table_name = $type . 'meta'; 

    if (empty($wpdb->$table_name)) 
     return false; 

    return $wpdb->$table_name; 
} 

phpxref.ftwr.co.uk/wordpress/nav.html?wp-includes/meta.php.source.html#l811

+0

덕분에, 나는에 따라 더욱라고 생각 무슨 일이 일어나고 있는지 이해. clpr_store_phone 필드에 값이있는 경우 검색하는 방법은 어떻게됩니까? – fightstarr20

+0

당신은 그냥'get_metadata'를 사용하는 것과 같습니다. – ninnypants

+0

나는이 줄을 update_metadata ($ _ POST [ 'taxonomy'], $ term_id, 'clpr_store_phone', $ _POST [ 'clpr_store_phone'])라고합니다. clpr_store_phone 데이터를 저장하고 있습니다. 이걸 get_metadata 명령으로 바꾸려면 어떻게해야합니까? – fightstarr20

관련 문제