Skip to content

Instantly share code, notes, and snippets.

@paulgibbs
Last active December 17, 2015 10:29
Show Gist options
  • Save paulgibbs/5595124 to your computer and use it in GitHub Desktop.
Save paulgibbs/5595124 to your computer and use it in GitHub Desktop.
<?php
// Not tested, but it should work
function pg_adjust_main_query( $query ) {
/**
* If we're not on the blog posts index page,
* or if we're not modifying the main query,
* then bail out.
*/
if ( ! $query->is_home() || ! $query->is_main_query() )
return;
$query->set( 'meta_key', 'YOUR_META_KEY_HERE' );
$query->set( 'orderby', 'meta_value_num' );
}
add_action( 'pre_get_posts', 'pg_adjust_main_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment