WordPress.org

Ready to get started?Download WordPress

Forums

Media Tags
[resolved] How to fetch image url and description? (3 posts)

  1. sporkme
    Member
    Posted 1 year ago #

    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/

  2. jamieisboss
    Member
    Posted 1 year ago #

    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

  3. sporkme
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.