WordPress: too clever for its own documentation!
July 21st, 2010 by Sarah KingAny time you start using Widgets you forgo control and sometimes you need to take it back! A while ago I needed to control the sort orderĀ of the Links widget and found the “right way” to do it. Today, I needed it again but could I find the documentation anywhere?
In the end I found it at the bottom of a thread answered by Pinoy.ca.
All you need to do is find the functions.php file for your theme and add
function widget_links_args_filter($args) {
$args['orderby'] = 'rating'; // Sort links by rating
$args['order'] = 'DESC'; // descending
return $args;
}
add_filter('widget_links_args','widget_links_args_filter');
Its easy to understand what you’re doing once you have that small example. A shame, I guess, that sort order isn’t able to be set in the widget itself but if you need to make the change this is so much safer than messing with the source code as some sites recommend.
widget_links_args – try searching on Google or WordPress.org, you won’t find any official documentation for this function. Crazy!
