WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. surfsup74
    Member
    Posted 1 year 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.
    Thanks.

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

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

  2. keesiemeijer
    moderator
    Posted 1 year ago #

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

    <?php
    $media_items = get_attachments_by_media_tags('media_tags=home-portfolio');
    $media_items = array_reverse($media_items);
    ?>
  3. surfsup74
    Member
    Posted 1 year ago #

    Yes sir - that worked! Thanks

  4. Paul Menard
    Member
    Plugin Author

    Posted 1 year ago #

    @surfsup74,

    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

About this Topic