• Resolved surfsup74

    (@surfsup74)


    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>
                '; }
         }  ?>

    https://www.ads-software.com/extend/plugins/media-tags/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    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);
    ?>

    Thread Starter surfsup74

    (@surfsup74)

    Yes sir – that worked! Thanks

    Plugin Author Paul Menard

    (@pmenard)

    @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’.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Order of attachments’ is closed to new replies.