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

WP SITES

2784

Original Genesis Tutorials & 6000+ Guaranteed Code

Snippets

  • Consultation
  • Full Access
  • Log in

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

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags