Media Tags
[resolved] Order of attachments (4 posts)

  1. surfsup74
    Posted 3 years ago #

    I need to change the order of the $fullSize images that are output by the code below. Currently it is showing the oldest image first. I would like the latest (most recently uploaded image) to display first. I have tried adding orderby= & order= to the get_attachments_by_media_tags args but it does nothing.

    <?php $media_items = get_attachments_by_media_tags('media_tags=home-portfolio'); ?>
                if ($media_items) {
                foreach ($media_items as $mymedia) {
                $fullSize = wp_get_attachment_url($mymedia->ID);
                $image_caption = $mymedia->post_excerpt;
                echo '
                        <h4>'. $image_caption .'</h4>
                        <img src="'.$fullSize.'" alt="'. $image_caption .'" />
                '; }
         }  ?>


  2. keesiemeijer
    Posted 3 years ago #

    I don't know the plugin, but you could try to reverse the output from get_attachments_by_media_tags() with array_reverse

    $media_items = get_attachments_by_media_tags('media_tags=home-portfolio');
    $media_items = array_reverse($media_items);
  3. surfsup74
    Posted 3 years ago #

    Yes sir - that worked! Thanks

  4. Paul Menard
    Plugin Author

    Posted 3 years ago #


    While you have a solution provided by @keesiemeijer, Allow me to provide a better more flexible solution.

    The Media-Tags function get_attachments_by_media_tags() supports many of the same query arguments as get_posts. So you can pass 'orderby' into the function arguments as well as 'order'.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Media Tags
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic