Document library sort options
Document Library Pro comes with two options for sorting the document library when it first loads. Once the library has loaded, users can click on a column heading to sort by that column.
sort_by option sets which column should be used for sorting the library by when it is first displayed. Defaults to
date which is the date the document was published.
You can order by any column in the library, or by any of the following keywords (whether or not they are included in your library):
id– sort by document ID
title– sort by document title
menu_order– sort by the ‘order’ option (as listed in your site's primary menu)
date– sort by the publish date of the document (note: see here to sort by custom field date columns)
name– sort by document ‘slug’
modified– sort by last modified date
author– sort by author name
comment_count– sort by number of comments
rand– random order
In addition, if you are not using the lazy load option, you can sort by any other text-based column present in the library. E.g.
For lazy loaded libraries, you can only sort by the keywords listed above. This is because the sorting is handled by the server when the products are retrieved from the database.
Sort using keyword:
[doc_library content="title,content" sort_by="menu_order"]
Sort using content column in library:
[doc_library content="image,title,content,author" sort_by="content"]
Sort using custom field column in library:
[doc_library content="image,title,excerpt,cf:event" sort_by="cf:event"]
The direction to use for sorting by when the library is first displayed. Can be either
asc for ascending order or
desc for descending order.
desc for date-based sorting, and
asc for everything else, but you can override using this option. For example, if you wanted to alphabetize the library by listing items in alphabetical order, then the default will be correct.
[doc_library content="title,content" sort_by="date" sort_order="asc"]
Can I sort by multiple columns?
No, this is not currently possible. The library can only be sorted by a single column.
Can I sort the library by number?
You can only sort a column numerically if you are using a "Number" custom field created using the plugin Advanced Custom Fields and lazy load should be off. Otherwise, the library is sorted alphabetically rather than numerically. This applies to all text-based columns including custom fields and taxonomies.
If you’re using custom fields or taxonomies to store numbers instead of text, then you may wish to sort the library in number order. There is no option for this unless you are using Advanced Custom Fields, but you can achieve this by adding the numbers in a format that will make sense when ordered alphabetically. For example:
- If you add numbers in the format 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 and 11, then they will be sorted in the following order – 1, 10, 11, 2, 3, 4, etc. This does not look correct.
- If you’re sorting by a custom field containing numbers 01, 02, 03, 04, 05, 06, 07, 08, 09, 10 and 11, then they will be sorted correctly both alphabetically and numerically.