Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Page that have reviews assigned to them are given a special number that determines their ranking.
- // The page ranking is calculated from the number of assigned reviews and their ratings.
- $query = new WP_Query([
- 'meta_query' => [
- 'relation' => 'OR',
- ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'], // this comes first!
- ['key' => '_glsr_ranking', 'compare' => 'EXISTS'],
- ],
- 'order' => 'DESC',
- 'orderby' => 'meta_value_num',
- 'post_status' => 'publish',
- 'post_type' => 'page', // change this as needed
- 'posts_per_page' => 10, // change this as needed
- ]);
- if( $query->have_posts() ) {
- while( $query->have_posts() ) {
- $query->the_post();
- $average = sprintf( '%s (average rating: %s)',
- get_the_title(),
- get_post_meta( $post->ID, '_glsr_average', true )
- );
- $ranking = sprintf( '%s (ranking: %s)',
- get_the_title(),
- get_post_meta( $post->ID, '_glsr_ranking', true )
- );
- apply_filters( 'glsr_debug', 'Site Reviews is not installed', $average, $ranking );
- }
- wp_reset_postdata();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement