Skip to content

Instantly share code, notes, and snippets.

@peterwilsoncc
Created October 31, 2012 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterwilsoncc/3984736 to your computer and use it in GitHub Desktop.
Save peterwilsoncc/3984736 to your computer and use it in GitHub Desktop.
filter_pre_get_posts help
function filter_pre_get_posts(&$query) {
if ( $query->is_home AND $query->is_main_query() ) {
$query->set('meta_key', 'my_key');
$query->set('orderby', 'meta_value_num date');
// should sort by meta-value as number, then by date
// actually sorts by date and ignores anything with my_key set
$query->set('orderby', 'meta_value_num'); //works as expected (sorts by my_key)
$query->set('orderby', 'date'); //works as expected (sorts by date)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment