Support » Plugin: Media Tags » Order of attachments

  • Resolved 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.

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

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



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

    Yes sir – that worked! Thanks

    Plugin Author Paul Menard



    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.