WPIntell

Source evidence

WP_Query

ACF: Star Rating Field · support · 2014-12-29T03:16:00+00:00

complaintsentiment
mediumseverity
0.86relevance
2replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

5 / 31 rows with source links

16.1% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

26 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
oniontaylor unresolved
Love your plugin so far! -Quick question though, if I wanted to sort a page using WP_Query using the average (‘avrg’) star rating, how would I do so? https://wordpress.org/plugins/acf-starrating/ Honestly when I created the plugin, I had not thought about sorting (I forgot about it and I didn’t want to create a lot of fields) ((. In the next release, I planned to think about adding fields in the “meta” tables. Now there are two ways to sort the data (they both are not good): 1. Sort the data array after loading from the database. 2. The use of the filter posts_order (with MYSQL string functions). Example: <?php // WP_Query: $args = array( 'post_type' => 'ideas', 'meta_key' => 'ideas_rating', 'numberposts' => '-1' ); add_filter( 'posts_orderby', 'filter_rating_query'); $query = new WP_Query; $my_posts = $query->query($args); remove_filter( 'posts_orderby', 'filter_rating_query'); foreach( $my_posts as $my_post ){ print $my_post->post_title; the_field( 'ideas_rating', $my_post->ID ); } // Filter function: function filter_rating_query( $query ) { global $wpdb; $query = ' SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(' . $wpdb->postmeta . '.meta_value, \'\"\', \'\'), \';s:5:votes\', 1), \':\', -1) DESC'; return $query; } ?> Thanks for the response!

Comments

2 shown
lienann 2014-12-29T11:54:00+00:00

Honestly when I created the plugin, I had not thought about sorting (I forgot about it and I didn’t want to create a lot of fields) ((. In the next release, I planned to think about adding fields in the “meta” tables. Now there are two ways to sort the data (they both are not good): 1. Sort the data array after loading from the database. 2. The use of the filter posts_order (with MYSQL string functions). Example: <?php // WP_Query: $args = array( 'post_type' => 'ideas', 'meta_key' => 'ideas_rating', 'numberposts' => '-1' ); add_filter( 'posts_orderby', 'filter_rating_query'); $query = new WP_Query; $my_posts = $query->query($args); remove_filter( 'posts_orderby', 'filter_rating_query'); foreach( $my_posts as $my_post ){ print $my_post->post_title; the_field( 'ideas_rating', $my_post->ID ); } // Filter function: function filter_rating_query( $query ) { global $wpdb; $query = ' SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(' . $wpdb->postmeta . '.meta_value, \'\"\', \'\'), \';s:5:votes\', 1), \':\', -1) DESC'; return $query; } ?>

oniontaylor 2014-12-29T12:14:00+00:00

Thanks for the response!