I got code from here to help me get started on this project:
<a href="http://wp-types.com/forums/topic/multiple-sort-criteria/">http://wp-types.com/forums/topic/multiple-sort-criteria/</a>
It works great with a few tweaks. Here are my tweaks:
add_filter('parse_query', 'add_custom_fields_to_properties_query'); function add_custom_fields_to_properties_query($wp_query) { if (in_array('properties', (array)$wp_query->get('post_type'))) { $meta_query = array(); $meta_query[] = array('key' => 'wpcf-price'); $wp_query->set('meta_query', $meta_query); add_filter('posts_orderby', 'custom_order'); } return $wp_query; } function custom_order($orderby) { global $wpdb; return $wpdb->postmeta.'.meta_value ASC, CAST(mt1.meta_value AS UNSIGNED) DESC'; }
The problem is that this affects every instance where my Properties are viewed – even in the wp-admin area – OUCH!
Is it possible to limit the use of this function to just one View? It works superbly on categorical listing on the public side.