Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

Reply To: Sorting an archive loop by a Types custom field

$
0
0

For those just tuning in and having the same problem as I did (menus disappearing when using the code above*) this code from Caridad http://wp-types.com/forums/topic/sort-the-results-of-a-taxonomy-archive-page/ worked perfectly for me:

add_filter('pre_get_posts', 'sort_my_archive');
function sort_my_archive($q) {
 if ($q->is_archive) {
   $q->set('meta_key', 'wpcf-fieldname');
   $q->set('orderby', 'meta_value');
   $q->set('order', 'ASC');
 }
 return $q;
}

*Not saying anything is wrong with Luoy's code – more likely a conflict with my theme.


Viewing all articles
Browse latest Browse all 20145

Trending Articles