• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2665

Original Genesis Tutorials & 5000+ Guaranteed Code

Snippets

  • Support
  • Newsletter
  • Videos
  • Log in

Premium Member? - Request custom code

Order Posts By Rating Value In Taxonomy Term Archive

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.

Custom Post Type Taxonomy Terms

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

PHP Code

template_include

get_body_class

if else

array

class_exists

foreach

sprintf

add_action

printf

variable

Advertise · WPEngine · Genesis · Log in

  • How Premium Membership Works
  • Sign Up
  • Support
  • Subscription Details/Invoice
  • Tagged Tutorials
  • Access-Download Problems