/**
* Entry Rating
*
*/
function be_entry_rating() {
if( ! ( class_exists( 'Mediavine\MV_DBI' ) ) )
return;
/**
* There's currently a bug where some of the creations are storing associated_posts
* with quotes and some without. Ex: [123] and ["456"].
* mv_get_post_creations() only finds the quoted ones, which is why we're
* doing the complex query below.
*
* Once that bug is resolved, the code below can be simplified to:
* https://gist.github.com/billerickson/8c69e26a7e6a0b1efdce9c30ad680adf
*
*/
$creations = \Mediavine\MV_DBI::get_models(['mv_creations'])->mv_creations->where( [
['associated_posts', 'LIKE', '%"' . get_the_ID() . '"%', 'or'],
['associated_posts', 'LIKE', '%[' . get_the_ID() . ']%' ]]
);
if( empty( $creations ) || ! is_array( $creations ) || empty( $creations[0]->rating ) )
return;
echo '<span class="entry-rating">' . str_repeat( '★', round( $creations[0]->rating ) ) . '</span>';
}