Ad

How To Access Meta Value Under Image Link In Wordpres

- 1 answer

**meta_value**:a:1:{i:0;s:105:"http://localhost/wordpress/wp-content/uploads/event-manager-uploads/event_banner/2020/07/diabetic_1-3.jpg";}

meta_key:_event_banner

while($res = mysqli_fetch_array($query)) 
                {
                    $i++;
                    // $img_src=wp_get_attachment_image_src(get_post_thumbnail_id($res['image']));
                    // $img_src_url=$img_src[0];
                    $id=$res['post_id'];
                    $post = get_post($res['post_id'] );
             
                  ?>
                    <div class="maindiv">
                  <div class="notification">
                      <img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($id) );?>"></td>
                  <img src="<?php echo $post->_event_banner;?>"></td> 
                  </div>
                  <div class="notification1">
                  <h2><a href="<?php echo $res['permalink'] ?>"><?php echo $res['post_title']?></a></h2>
                  <h6><?php echo $res['date']?></h6>
              </div>
            </div>
                <?php
            }

how to display image give me some reference I need help on how to access the image in meta key use and filter I have not idea in meta key use give me idea... it's very important

Ad

Answer

So not sure how you're saving your meta_key in the first place? It looks like what you have is a serialized array with just a single, numerically indexed entry. So what you probably want to do is change wherever that's saved to just store the URL?

That said, you could access that meta value like this:

$banner_src = maybe_unserialize( get_post_meta( $post->ID, '_event_banner', true ) );
$banner_src = is_array( $banner_src ) ? $banner_src[0] : $banner_src;

And then display the banner like:

<img src="<?php echo $banner_src; ?>" />
Ad
source: stackoverflow.com
Ad