Created
January 23, 2018 22:28
-
-
Save brandondove/76c69b8a8058e863d610719b9860596d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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