Created
September 30, 2012 01:11
-
-
Save maor/3805555 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 | |
/* [http://on.fb.me/UAe3H9] */ | |
/* | |
* Posts that have the 'mc_order_key' custom field, and that their (numeric) value is low | |
* will be shown first. If you wish to reverse the order, change the 'order' parameter to | |
* 'DESC'. Also make sure to change the meta key. | |
*/ | |
function mc_reorder_search_results( $query ) { | |
/* Let's make sure we're on the search page, and running on the main query. */ | |
if ( $query->is_search() && $query->is_main_query() ) { | |
$query->query_vars = array_merge( $query->query_vars, array( | |
'order' => 'ASC', /* Deafult is DESC, set for ASC to reverse. */ | |
'orderby' => 'meta_value', | |
'meta_key' => 'mc_order_key' /* Change this key to match yours! */ | |
) ); | |
} | |
} | |
add_action( 'pre_get_posts', 'mc_reorder_search_results' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment