在我目前的wordpress自定义项目中,我为一些自定义帖子类型提供了一些自定义图片上传字段。 在前端,我将从这些自定义字段接收数据,即。这些自定义图像的URL使用函数get_post_meta()。但在这种情况下,我获得通过元框上传的原始完整大小的图像。如何获取上传的元字段的缩略图。有多个图像字段用于post type.Here是我目前获取图片的代码
$meta = get_post_meta( $post_id );
//print_r($meta);
$client = $meta['client'][0];
$channel = $meta['channel'][0];
$logistics = $meta['logistics'][0];
$head = $meta['headline2'][0];
$img1 = isset($meta['image1'])?$meta['image1']:'';//image field 1
$img2 = isset($meta['image2'])?$meta['image2']:'';//image field 2
$img3 = isset($meta['image3'])?$meta['image3']:'';//image field 3
答案 0 :(得分:1)
Please check this link for adding images to posts.
http://justintadlock.com/archives/2007/10/27/wordpress-custom-fields-adding-images-to-posts
OR
Try wp_get_attachment_image_src()
$attachment_id = get_field('field_name');
$size = "medium"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );