Last active
August 29, 2015 14:02
-
-
Save craiggrella/b45e792f35bd4de5f5b9 to your computer and use it in GitHub Desktop.
Change Post Sort Order by Meta Key in WordPress
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
// change sort order of posts based on meta | |
function change_order_for_post_archive( $query ) { | |
//only show future events and events in the last 24hours | |
if ( $query->is_main_query() && is_post_type_archive('attorney') ) { | |
$query->set( 'meta_key', 'ecpt_position' ); | |
$query->set( 'orderby', 'meta_value' ); | |
$query->set( 'order', 'ASC' ); | |
} | |
} | |
add_action( 'pre_get_posts', 'change_order_for_post_archive' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment