Title: Cant sort alphabetically
Last modified: August 21, 2016

---

# Cant sort alphabetically

 *  [rescamilla](https://wordpress.org/support/users/rescamilla/)
 * (@rescamilla)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/cant-sort-alphabetically/)
 * Hi there. Awesome plugin! I’m using it on a large municipal website to list public
   documents (pdf’s).
 * I have tried everything and cannot get “order” or “orderby” to list the pdf’s
   in alphabetical order. I have finally figured out that the only way to get this
   done is to make sure I batch upload the documents (in wordpress>Media>Add New
   >Select Files) in alphabetical order to begin with.
 * Any ideas why I cannot get the shortcode to do this for me?
 * Thanks.
 * -Ray
 * [https://wordpress.org/plugins/media-tags/](https://wordpress.org/plugins/media-tags/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Thread Starter [rescamilla](https://wordpress.org/support/users/rescamilla/)
 * (@rescamilla)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/cant-sort-alphabetically/#post-4962056)
 * After searching the wordpress codex I found this and it seems to work so far.
 * Use this in the shortcode: orderby=”title”
 * -Ray
 *  Plugin Author [Paul Menard](https://wordpress.org/support/users/pmenard/)
 * (@pmenard)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/cant-sort-alphabetically/#post-4962082)
 * [@rescamilla](https://wordpress.org/support/users/rescamilla/),
 * Great. Glad to see you got this figured out. Let me know if you run into any 
   more issues or have other questions.
 *  Thread Starter [rescamilla](https://wordpress.org/support/users/rescamilla/)
 * (@rescamilla)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/cant-sort-alphabetically/#post-4962100)
 * Well since you ask…..
 * I have been trying to figure out how to show the filename extension by default.
   My pdf’s show in the li brackets without an extension. Would like to change that.
 * Thanks!
 * -Ray
 *  Plugin Author [Paul Menard](https://wordpress.org/support/users/pmenard/)
 * (@pmenard)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/cant-sort-alphabetically/#post-4962148)
 * [@rescamilla](https://wordpress.org/support/users/rescamilla/),
 * There is not a default way to do this. But it is possible. As part of the shortcode
   you are using (or if you are using the template function it works the same) there
   is a default display function called ‘default_item_callback’ located in the mediatags_shortcodes.
   php file.
 * You would need to copy this function and add it to your theme’s functions.php
   and change the name of the function to something else. The change the logic to
   display what you want.
 * Then when you use the shortcode add the parameter ‘ display_item_callback=”your_function_name”‘
   where ‘your_function_name’ if your new function name.
 *  Thread Starter [rescamilla](https://wordpress.org/support/users/rescamilla/)
 * (@rescamilla)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/cant-sort-alphabetically/#post-4962163)
 * Thats what I love about this plugin! I am already using a custom function in 
   my functions.php to show the file description as text above the filename, works
   like a charm. I’m just not sure what part of the logic to change to show the 
   file extension though. I think it has something to do with the “wp_get_attachment_link(
   $post_item->ID)” bit.
 * -Ray
 *  Plugin Author [Paul Menard](https://wordpress.org/support/users/pmenard/)
 * (@pmenard)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/cant-sort-alphabetically/#post-4962175)
 * [@rescamilla](https://wordpress.org/support/users/rescamilla/),
 * If you want to get the filename extension you can use the following line;
 * $file_ext = pathinfo(basename(wp_get_attachment_url($post_item->ID)), PATHINFO_EXTENSION);
 * To break this down for you here is an explanation of the parts.
 * wp_get_attachment_url($post_item->ID) – This will get the URL to the file. Something
   like [http://example.net/wp-content/uploads/filename.pdf](http://example.net/wp-content/uploads/filename.pdf)
 * Then the PHP function basename() is called to remove the path and return just
   the filename.
 * Then the PHP function pathinfo() is called. We pass in the filename from the 
   basename() function and the second parameter tells the function to just return
   the file extension.
 * If I’m wrong in my assumption and you just want the filename extension shown 
   for the filename as displayed via Media-Tags then you can simply modify the line
   in your output template function. As part of the wp_get_attachment_link() function
   you need to pass in the link text parameter. This is the 5th parameter of the
   function. See my code suggestion below.
 * return ‘<li class=”media-tag-list” id=”media-tag-item-‘.$post_item->ID.'”>’. 
   wp_get_attachment_link($post_item->ID, false, false, false, basename(wp_get_attachment_url(
   $post_item->ID))) .”;
 *  Thread Starter [rescamilla](https://wordpress.org/support/users/rescamilla/)
 * (@rescamilla)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/cant-sort-alphabetically/#post-4962183)
 * Yep that got the job done. Now I just need to find your donate link. Thanks for
   the great support.
 * If anyone else is reading this, here is a [screenshot](https://dl.dropboxusercontent.com/u/39676163/Screen%20Shot%202014-05-31%20at%209.15.30%20AM.png)
   of the results I was trying to get, and got, with Paul’s help.
 * Only thing missing was the closing `</li>` in the example code above. Here is
   the exact code I am using:
    `return ''.$post_item->post_content.'<li class="media-
   tag-list" id="media-tag-item-'.$post_item->ID.'">'. wp_get_attachment_link($post_item-
   >ID, false, false, false, basename(wp_get_attachment_url($post_item->ID))) .'';`
 *  Plugin Author [Paul Menard](https://wordpress.org/support/users/pmenard/)
 * (@pmenard)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/cant-sort-alphabetically/#post-4962187)
 * [@rescamilla](https://wordpress.org/support/users/rescamilla/),
 * Ah. Sorry. I missed that closing `<li>` when I copied it. Thanks for catching
   that. Good luck.

Viewing 8 replies - 1 through 8 (of 8 total)

 The topic ‘Cant sort alphabetically’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/media-tags.svg)
 * [Media Tags](https://wordpress.org/plugins/media-tags/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/media-tags/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/media-tags/)
 * [Active Topics](https://wordpress.org/support/plugin/media-tags/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-tags/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-tags/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [Paul Menard](https://wordpress.org/support/users/pmenard/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/cant-sort-alphabetically/#post-4962187)
 * Status: not resolved