This PHP code, added to your child themes functions file, enables you to order you posts using any WP_Query parameters.
I this case, we order custom post type entries published for the industry_type taxonomy term, by ascending order from highest rating to lowest using ASC For descdending order from lowest to highest, use DESC.
add_action( 'pre_get_posts', 'order_taxonomy_archive' );
function order_taxonomy_archive( $query ) {
if ( $query->is_main_query() AND $query->is_tax('industry-type') ) {
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'ASC' );
}
}
The rating is added using a rating plugin however the value is saved as a custom field enabling us to use meta_value_num
Video Demo
Shows you how to order your posts by the custom field value of the posts rating.
Was This Tutorial Helpful?