根据ID获取post_meta图片网址

时间:2020-02-11 17:45:04

标签: php database wordpress

因此,我想从数据库中提取一张我的post_meta上的图片网址,但是我不确定该如何定位。

这是我要采取的步骤:

以下是数据库wp_postmeta表下的内容:
enter image description here

如果我导航到wp_posts-我收到的meta_value帖子中包含我的网址,例如:
enter image description here


当我做$test = get_post_meta($post->ID, 'full_image');时,我得到以下信息:
enter image description here

如何基于wp_posts$post->ID提取图片网址?我很难确定它的位置。


更新

如果我做var_dump(get_attached_media('image', $post->ID));-我得到以下结果:
enter image description here

如何获取guid网址?

3 个答案:

答案 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。

相关问题