简体   繁体   中英

Get post_meta image url based on ID

So i'd like to extract the image url from the database on one of my post_meta, but I'm unsure how to target that.

Here is the steps that I'm taking:

Here is what's under the wp_postmeta table in the database:
在此处输入图片说明

If I navigate to wp_posts - I get the meta_value post with my url inside as such:
在此处输入图片说明


When I do $test = get_post_meta($post->ID, 'full_image'); I get the following:
在此处输入图片说明

How does one extract the image url from wp_posts based on $post->ID ? I'm having the hardest time targeting it.


UPDATE :

If I do var_dump(get_attached_media('image', $post->ID)); - I get the following results:
在此处输入图片说明

How do I grab the guid url?

If I'm understanding correctly, you're making it too hard. All you need to is use wp_get_attachment_image_src

$test = get_post_meta($post->ID, 'full_image', true);
$image = wp_get_attachment_image_url( $test[0] );

To grab the guid from your array, you will have to call it like that:

<?php    
    $image = get_attached_media('image', $post->ID);
    $image_guid = $image['guid'];
    echo $image_guid; //will echo the guid URL
?>

Got it working using this method:

$this->set_full_image(wp_get_attachment_image_url( get_post_meta($post->ID, 'full_image', true), 'large'));

The reason that I wasn't getting any results back is because get_post_meta was returning an array and not a single value so I had to set true at the end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM