Possible to create a permalink to sort with meta_key?

What about something like that?

function wpse139657_orderby(){
    if( isset($_GET['orderby']) ){
        $order = $_GET['order'] or 'DESC';
        set_query_var('orderby', 'meta_value_num');
        set_query_var('meta_key', $_GET['orderby']);
        set_query_var('order', $order);
    }
}

add_filter('pre_get_posts','wpse139657_orderby');

In this way you can call your urls with a ?orderby=rank suffixed and it should do the trick. You can also have an optional order parameter, should you want to implement it.

Leave a Comment