2013-10-25 33 views
1

這就是我所有的代碼....可能我做了錯誤的事情導致保存功能不起作用。 我不在哪裏以及如何做了一個錯誤.. 我創建了CPT和揚聲器選擇的元框選擇項目倍數和另一個metabox與廣播流的細節....可能我把許多meta_boxes。 ..我不知道 幫我保存Wordpress的metabox dara不起作用

<?php 
add_action('init', 'speaker_manager'); 

function speaker_manager() { 
    $labels = array(
     'name'    => __('Speakers'), 
     'singular_name'  => __('speaker'), 
     'add_new'   => __('Aggiungi Speaker'), 
     'add_new_item'  => __('Nuovo Speaker'), 
     'edit_item'   => __('Modifica Speaker'), 
     'new_item'   => __('Nuovo Speaker'), 
     'all_items'   => __('Elenco Speaker'), 
     'view_item'   => __('Visualizza '), 
     'search_items'  => __('Cerca '), 
     'not_found'   => __('Speaker non trovato'), 
     'not_found_in_trash' => __('Speaker non trovato nel cestino'), 
     ); 

    $args = array(
     'labels'    => $labels, 
     'public'    => true, 
     'show_ui' => true, 
     'rewrite'   => array('slug' => 'speaker'), 
     'publicly_queryable' => true, 
     'has_archive'  => true, 
     'capability_type' => 'post', 
     'hierarchical'  => false, 
     'menu_icon' => get_stylesheet_directory_uri() . '/images/speakers.png', 
     'menu_position'  => 5, 
     'supports'   => array(
     'title', 
     'editor', 
     'thumbnail' 
     ), 
     ); 

    register_post_type('speaker', $args); 
} 

if (function_exists('add_theme_support')) { 
    add_theme_support('post-thumbnails'); 
    set_post_thumbnail_size(220, 150); 
} 

add_action("admin_init", "speaker_manager_add_meta"); 

function speaker_manager_add_meta(){ 
    add_meta_box("speaker-meta", "Social", "speaker_manager_meta_options", "speaker", "normal", "high"); 
} 

function speaker_manager_meta_options($post) 
{ 
    ?> 
     <p>Aggiungi i profili social:</p> 
     <p><label for="speaker_social_link">Link al sito</label> 
     <input type="text" id="speaker_social_link" name="speaker_social_link" 
     value="<?php echo get_post_meta($post->ID, 'speaker_social_link', true); ?>"/></p> 

    <?php 
} 

add_action('save_post', 'save_speaker_social_link'); 
function save_speaker_social_link($post_id) 
{ 
    global $post; 
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ 
     //if you remove this the sky will fall on your head. 
     return; 
    }else{ 
     update_post_meta($post_id, 'speaker_social_link', esc_url($_POST['speaker_social_link'])); 

    } 
} 

add_filter('manage_speaker_posts_columns', 'columns_speaker'); 
function columns_speaker($old_columns) 
{ 
    $speaker_col = array(
     'cb'  => '<input type="checkbox">', 
     'img' => 'Immagine', 
     'title' => __('Speakers'), 
     'link' => 'link', 
     ); 
    return $speaker_col; 
} 

add_action('manage_speaker_posts_custom_column', 'get_speaker_columns', 10, 2); 
function get_speaker_columns($col, $post_id) 
{ 
    switch($col) { 
     case 'img': 
     if(has_post_thumbnail($post_id)) { 
      echo get_the_post_thumbnail($post_id); 
     } else { 
      echo 'Nessuna immagine!'; 
     } 
     break; 
     case 'link': 
     echo get_post_meta($post->ID, 'speaker_social_link', true); 
     default: 
     break; 
    } 
} 
+0

如果您以合理的方式縮進您的代碼,那麼對於您和我們而言,***會更容易***。 – brasofilo

+0

您確定您使用正確的語法:<?php update_post_meta($ post_id,$ meta_key,$ meta_value,$ prev_value); ''在你的代碼後ID是$ post_id,$ meta_key是'speaker_id',$ meta_value是$ _POST ['speaker_id']。但是你沒有任何名稱爲speaker_id的表單域,它必須爲schdule_dj啓動並傳輸。檢查你的if語句,並寫入error_log();查看save函數是否獲取post_id。你在哪裏編碼add_action('admin_menu','palinsesto_box');'? –

+0

@b__我確實...可以幫助我嗎...我無法在自定義列中看到鏈接 – zen

回答

0

您的代碼保存在元框中的字段,但是你應該尋找在WPSE的add_meta_box + save_post很好的例子。

對於列,你不能代替原件,但添加自己(和你不需要cb):

function columns_speaker($old_columns) 
{ 
    $new_columns = array(
     'img' => 'Immagine', 
     'title' => __('Speakers'), 
     'link' => 'link', 
    ); 
    return array_merge($new_columns, $old_columns); 
} 

get_speaker_columns你得到一個錯誤,這不是$post->ID$post_id

+1

非常感謝您的回答以及鏈接 – zen