2017-09-07 74 views
0

以下是我在functions.php的代码,仍然无法在博客的帖子类型中设置为精选图片。如何在帖子类型为ACF FORM中显示精选图片为图片字段

add_action('acf/save_post', 'acf_set_featured_image'); 

function acf_set_featured_image($post_id){ 
    $value = get_field('daily_selfie', $post_id); 

    if($value != ''){ 
     add_post_meta($post_id, '_thumbnail_id', $value); 
    } 

    return $value; 
}

回答

1

试试这个

function acf_set_featured_image($value, $post_id, $field ){ 

    if($value != ''){ 
     //Add the value which is the image ID to the _thumbnail_id meta data for the current post 
     add_post_meta($post_id, '_thumbnail_id', $value); 
    } 
    return $value; 
} 

// acf/update_value/name={$field_name} - filter for a specific field based on it's name 
add_filter('acf/update_value/name=foo', 'acf_set_featured_image', 10, 3); 
相关问题