Support » Plugin: Media Tags » How to fetch image url and description?

  • Resolved sporkme

    (@sporkme)


    Hello,

    I’m trying to work this into a template, and while the below does match, but I’m lost as to just what the object returned in $media_items is and how I access the image url and description:

    $media_items = get_attachments_by_media_tags('media_tags=home-slider');
    if ($media_items) {
            var_dump($media_items);
            }
    }

    The var dump is showing me that I apparently have a bunch of arrarys inside of arrays, and I’m assuming there’s a proper way to get at that.

    http://wordpress.org/extend/plugins/media-tags/

Viewing 2 replies - 1 through 2 (of 2 total)
  • I had a similar problem, inside the array are objects so you can access them like this:

    $media_items[0]->guid

    To loop through and extract the image urls and wrap them in image tage I used the following code:

    <?php $media_items = get_attachments_by_media_tags('media_tags=categpry');
    
    		$arrlength=count($media_items);
    		for($x=0;$x<$arrlength;$x++)
    		  {
    		  echo	'<img src=',$media_items[$x]->guid,' />';
    		  echo "<br>";
      }
      ?>

    Im very new at this so there might well be a better way but it worked for me

    Jamie

    I ended up doing something like this:

    $media_items = get_attachments_by_media_tags('media_tags=home-slider');
    if ($media_items) {
            foreach($media_items as $imgpost) { ?>
                    <?php $hsimg = wp_get_attachment_image_src( $imgpost->ID, full); ?>
                    <div class="home_slide">
                    <div class="gif">
                            <img class="imagefield imagefield-field_animation" width="1020" height="630" alt="" src="<?php echo $hsimg[0]; ?>" />
                            </div>
                            <div class="newbig home_title">
                                    <?php echo $imgpost->post_content; ?>
                            </div> <!-- end  home_title -->
                    </div> <!-- end home_slide -->
    <?php   }
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to fetch image url and description?’ is closed to new replies.