PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 26, 2022

[FIXED] how to access meta value under image link in wordpres

 August 26, 2022     meta-key, metadata, php, wordpress     No comments   

Issue

**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


Solution

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; ?>" />


Answered By - JBoss
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing