I am trying to:
Correct shortcodes that was previously display and now stops after updates.
I visited this URL:
I expected to see: ratings to display.
Instead, I got: blank on ratings elements.
I have [rating-average] shortcodes inside a template and display that template inside another template which uses to be display rating average. It was working just fine until I updated to WP 4.2.3 and all toolset to current version. It stops displaying rating average (see screenshots).
Here’s a detail...
I have [rating-average] shortcodes placed inside a template called [wpv-post-body view_template="display-overall-rating"] and place that display-overall-rating template inside another template called restaurants-details-single to display average rating for particular listing. Now since updating to latest WP and all toolsets to current version it stops display average rating.
I’ve been follow that there’s many issue relating to shortcodes and I appreciate toolset team hard work on this issues. 🙂
reference: https://toolset.com/forums/topic/wordpress-4-2-3-update-breaks-shortcodes/
Here’s my codes
Rating Average Shortcode
add_shortcode('rating-average', 'rating_average_func');
function rating_average_func()
{
global $post;
$args = array(
'post_type' => 'reviews',
'meta_key' => '_wpcf_belongs_' . $post->post_type . '_id',
'meta_value' => $post->ID,
);
$child_posts = get_posts($args);
$sum = 0;
$num = 0;
foreach ($child_posts as $child_post) {
$ratings = get_post_meta($child_post->ID, 'wpcf-ratings', true);
if($ratings)
{
$sum += $ratings;
$num ++;
}
}
$average = 0;
if($num>0)
{
$average = $sum/$num;
}
$res = $average;
if($average==0) $res = 0;
if($average>0.001 && $average<0.5)$res = 0.5;
if($average>0.501 && $average<1) $res = 1;
if($average>1.001 && $average<1.5) $res = 1.5;
if($average>1.501 && $average<2) $res = 2;
if($average>2.001 && $average<2.5) $res = 2.5;
if($average>2.501 && $average<3) $res = 3;
if($average>3.001 && $average<3.5) $res = 3.5;
if($average>3.501 && $average<4) $res = 4;
if($average>4.001 && $average<4.5) $res = 4.5;
if($average>4.501 && $average<5) $res = 5;
//... here put more condition ...
return $res;
}
Display Overall Rating Template
<div class="avg-rating fa stars-[rating-average]">
<div class="rating-box">
<span itemprop="aggregateRating" itemscope itemtype="<em><u>hidden link</u></em>">
<meta itemprop="ratingValue" content="Rated [rating-average] out of [reviews_total]"> from <span itemprop="ratingCount">[reviews_total]</span> reviews.
</span></div>
</div>
Restaurants Details Single
<!---TOP FULL WIDTH-->
<div>
<div>
<h3>[wpv-post-title]</h3>
[wpv-post-body view_template="Overall Rating"]
</div>
</div>
<!---CONTACTS & MAPS-->
<div>
<div>
[wpv-post-body view_template="map-content-single-post"]
[wpv-post-body view_template="business-address"]
Cuisine: [wpv-post-taxonomy type="cuisines"]
Category: [wpv-post-taxonomy type="restaurant-category"]
Serving Options: [wpv-post-taxonomy type="dining-options"]
</div>
<div>
<div>
[wpv-post-body view_template="contact-details"]
</div>
<div>[wpv-view name="Flex slider - main slider"]</div>
<div>[wpv-view name="Flex slider nav - thumbnails"]</div>
</div>
</div>
<!---MORE RATINGS-->
<div>
<div>
[wpv-post-body view_template="More Ratings"]
</div>
</div>
<!---FEAURES-->
<div>
<div>
[wpv-post-body view_template="restaurant-features-list"]
</div>
</div>
I’ll provide login credential in another reply.