因此,我想从数据库中提取一张我的post_meta上的图片网址,但是我不确定该如何定位。
这是我要采取的步骤:
如果我导航到wp_posts
-我收到的meta_value
帖子中包含我的网址,例如:
当我做$test = get_post_meta($post->ID, 'full_image');
时,我得到以下信息:
如何基于wp_posts
从$post->ID
提取图片网址?我很难确定它的位置。
更新:
如果我做var_dump(get_attached_media('image', $post->ID));
-我得到以下结果:
如何获取guid
网址?
答案 0 :(得分:0)
如果我理解正确,则说明您太难了。 您只需要使用wp_get_attachment_image_src
$test = get_post_meta($post->ID, 'full_image', true);
$image = wp_get_attachment_image_url( $test[0] );
答案 1 :(得分:0)
要从您的数组中获取guid
,您必须像这样调用它:
<?php
$image = get_attached_media('image', $post->ID);
$image_guid = $image['guid'];
echo $image_guid; //will echo the guid URL
?>
答案 2 :(得分:0)
使用此方法使其正常工作:
$this->set_full_image(wp_get_attachment_image_url( get_post_meta($post->ID, 'full_image', true), 'large'));
我没有得到任何结果的原因是因为get_post_meta
返回的是数组而不是单个值,所以我必须在末尾设置true。