No Value for $post->rating When Used In Loop In Functions.php
-
I have a loop of posts setup as a function in functions.php and within this I am trying to return the rating value for each post. When I use the loop outside of functions.php (hardcoded to the page) it works just fine. Only when the loop is used as a function in functions.php does it returns nothing. Anyone know why this might be happening?
function TheAdListTax ( $Tax , $Term , $BrandName , $BrandLink ) { ?> <div class="ListOfAdsWrap"> <div class="ListOfAds NewAds"> <h2 class="ListOfAdsLabel"><a href="<?php echo $BrandLink; ?>">New <?php echo $BrandName; ?> Commercials</a></h2> <ul class="AllAdsInList"> <?php $args = array( 'showposts' => 4, 'post_status' => 'publish', 'tax_query' => array( array( 'taxonomy' => $Tax, 'field' => 'slug', 'terms' => $Term ) ) ); $NewPosts = new WP_Query(); $NewPosts->query($args); while ($NewPosts->have_posts()) : $NewPosts->the_post(); ?> <?php $TheRating = $post->rating; $TopRating = 5; $RatingPercent = ($TheRating / $TopRating) * 100; $RoundRating = round($RatingPercent); ?> <li class="AdInTheList"> <div class="Stretch"> <div class="AdInListImage"> <?php the_post_thumbnail('medium'); ?> </div> <div class="AdInListInfo"> <div class="TopRow"> <div class="ReviewCount"><?php echo get_comments_number($Post->ID); ?> Reviews</div> <div class="ReviewStars"> <div class="RatingWrap"> <div class="TheRating" style="width:<?php echo $RoundRating; ?>%;"></div> </div> </div> </div> <div class="AdInListTitle"><?php the_title();?></div> <div class="SJbtns"> <ul> <li class="BlueBtn"><a href="<?php the_permalink(); ?>">Watch It</a></li> <li><a href="https://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>" target="_blank">Share It</a></li> </ul> </div> </div> </div> </li> <?php endwhile; wp_reset_query(); ?> </ul> <div class="Clear"></div> </div> </div> <?php }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘No Value for $post->rating When Used In Loop In Functions.php’ is closed to new replies.