2012-01-30 6 views

答えて

0

私はここに私の自己

答えるイメージという名前のカスタムフィールドにサムネイルURLを追加し、最終的なコードです。見つかりました

function w_thumbnail_src() { 
    if (has_post_thumbnail()) { 
     $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'emphasis'); 
     return $thumb[0]; // thumbnail url 
    } else { 
     return ''; // or a default thumbnail url 
    } 
} 


add_action('publish_page', 'add_custom_field_automatically', 'w_thumbnail_src'); 
add_action('publish_post', 'add_custom_field_automatically'); 
function add_custom_field_automatically($post_id) { 
global $wpdb; 
if(!wp_is_post_revision($post_id)) { 
add_post_meta($post_id, 'Image', w_thumbnail_src(), true); 
} 
} 
関連する問題