Skip to content

Instantly share code, notes, and snippets.

@brandondove
Created January 23, 2018 22:28
Show Gist options
  • Save brandondove/76c69b8a8058e863d610719b9860596d to your computer and use it in GitHub Desktop.
Save brandondove/76c69b8a8058e863d610719b9860596d to your computer and use it in GitHub Desktop.
<?php
// Hook into WordPress before the query runs
add_action( 'pre_get_posts', 'pj_sort_it_better' );
// Modifies the WP_Query object
function pj_sort_it_better( $query ) {
if ( is_page( 'The Page Name' ) ) {
$query->set( 'meta_key', 'pj-rating' );
$query->set( 'order', 'DESC' );
$query->set( 'orderby', 'meta_value' ); // or meta_value_num for numbers
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment