admin管理员组文章数量:1122832
First user fill this custom comment form.
This is my meta_key i want that i want to fetch. for every comment there are 10 rating.
I want to make below rating filter.But don't know how to start.
This is what i tried yet.
add_action( 'comment_post', 'show_message_function', 10, 2 );
function show_message_function( $comment_ID, $comment_approved ) {
$comment = get_comment( $comment_ID );
if( empty($comment) ) {
return;
}
$post = get_post( $comment->comment_post_ID );
$post_comments = get_comments( ['post_ID' => $post->ID ] );
$meta_value = get_comment_meta($comment->comment_ID);
d($post);
// d($post_comments);
d($meta_value);
die;
}
function d($data) {
echo '<pre>', print_r($data), '</pre>';
}
UPDATE: I created a post meta and save it in updated rating average every time a comment is posted.
Now want to make a filter as shown in above image, when any user click on checkbox against number of stars data must be filtered , and show those custom posts have average = chosen number of stars.
First user fill this custom comment form.
This is my meta_key i want that i want to fetch. for every comment there are 10 rating.
I want to make below rating filter.But don't know how to start.
This is what i tried yet.
add_action( 'comment_post', 'show_message_function', 10, 2 );
function show_message_function( $comment_ID, $comment_approved ) {
$comment = get_comment( $comment_ID );
if( empty($comment) ) {
return;
}
$post = get_post( $comment->comment_post_ID );
$post_comments = get_comments( ['post_ID' => $post->ID ] );
$meta_value = get_comment_meta($comment->comment_ID);
d($post);
// d($post_comments);
d($meta_value);
die;
}
function d($data) {
echo '<pre>', print_r($data), '</pre>';
}
UPDATE: I created a post meta and save it in updated rating average every time a comment is posted.
Now want to make a filter as shown in above image, when any user click on checkbox against number of stars data must be filtered , and show those custom posts have average = chosen number of stars.
Share Improve this question edited Sep 8, 2017 at 8:18 inrsaurabh asked Sep 8, 2017 at 4:32 inrsaurabhinrsaurabh 2033 silver badges14 bronze badges1 Answer
Reset to default 0I have create custom code for rating not for post type may be this code help you.
Step One:- Template file
<!-- begin content -->
<div id="content-wrap" class="top_pad review-planner" >
<div class="review-block">
<div class="container">
<h2><?php echo get_field('sub_title'); ?></h2>
<div class="all-list" style="display:none;">
<?php if(get_field('list_title')) { ?>
<span class="title"><?php echo get_field('list_title'); ?></span>
<?php } ?>
<ul class="list-item">
<li class="service"><span>Service:<i></i></span></li>
<li class="service2"><span>Uitsraling:<i></i></span></li>
<li class="service3"><span>Ligging:<i></i></span></li>
<li class="service4"><span>Eten&drinken:<i></i></span></li>
<li class="service5"><span>Parkeren:<i></i></span></li>
<li class="service6"><span>Prijs/kwaliteit:<i></i></span></li>
</ul>
<a class="reservBtn"><span>Schrijf een review</span></a>
</div>
</div>
</div>
<div class="user-reviews">
<div id="ajaxData">
<?php query_posts('post_type=reviews&showposts=-1');
if (have_posts()) : $i =1; while (have_posts()) : the_post();
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div class="publish-review">
<div class="icon" style="background:url(<?php if($url) { ?><?php echo $url; ?><?php } else { ?><?php bloginfo('template_url'); ?>/images/ic.png<?php } ?>) no-repeat center center; background-size:cover;" >
</div>
<div class="text-right">
<h2><span><?php the_title(); ?></span> <cite class="rating"></cite> <i>9,7</i><small><?php the_time('j F Y') ?></small></h2>
<div class="desc">
<p><?php echo get_field('description'); ?></p>
</div>
<ul>
<?php if(get_field('service_rating')) { ?>
<li class="service">Service: <i><?php echo get_field('service_rating'); ?></i></li>
<?php } ?>
<?php if(get_field('uitsraling_rating')) { ?>
<li class="service2">Uitsraling: <i><?php echo get_field('uitsraling_rating'); ?></i></li>
<?php } ?>
<?php if(get_field('ligging_rating')) { ?>
<li class="service3">Ligging: <i><?php echo get_field('ligging_rating'); ?></i></li>
<?php } ?>
<?php if(get_field('eten&drinken_rating')) { ?>
<li class="service4">Eten&drinken: <i><?php echo get_field('eten&drinken_rating'); ?></i></li>
<?php } ?>
<?php if(get_field('parkeren_rating')) { ?>
<li class="service5">Parkeren: <i><?php echo get_field('parkeren_rating'); ?></i></li>
<?php } ?>
<?php if(get_field('prijskwaliteit_rating')) { ?>
<li class="service6"> Prijs/kwaliteit: <i><?php echo get_field('prijskwaliteit_rating'); ?></i></li>
<?php } ?>
</ul>
</div>
</div>
<?php endwhile; wp_reset_query(); endif; ?>
</div>
</div>
</div>
<?php include 'reviewform.php'; ?>
<!-- finish content -->
jQuery(document).ready(function() {
jQuery('.header-wrap').click(function(event) {
event.stopPropagation();
});
setTimeout(function() {
jQuery('.all-list').fadeIn();
jQuery('#content-wrap').trigger('click');
}, 1000);
jQuery('.review-block .all-list ul.list-item li').each(function() {
var ffc = jQuery(this).find('span i').text();
if (jQuery(this).find('span i').text() == "NaN") {
jQuery(this).hide();
}
});
jQuery('#content-wrap').click(function() {
var url = "<?php bloginfo('template_url'); ?>/loadData.php";
jQuery.ajax({
type: "POST",
url: url,
data: "",
my_option: 'sucomp',
success: function(data) {
jQuery('#ajaxData').html(data);
var szs = jQuery('.user-reviews .publish-review').size();
var szs2 = szs * 10
serv = [];
serv2 = [];
serv3 = [];
serv4 = [];
serv5 = [];
serv6 = [];
var a1 = 0;
var a2 = 0;
var a3 = 0;
var a4 = 0;
var a5 = 0;
var a6 = 0;
jQuery('.user-reviews .publish-review').each(function(m) {
var comvar = 0;
var common = [];
jQuery(this).find('.text-right ul li').each(function() {
if (jQuery(this).hasClass('service')) {
var ths = jQuery(this).find('i').text();
serv.push(ths);
}
if (jQuery(this).hasClass('service2')) {
var ths = jQuery(this).find('i').text();
serv2.push(ths);
}
if (jQuery(this).hasClass('service3')) {
var ths = jQuery(this).find('i').text();
serv3.push(ths);
}
if (jQuery(this).hasClass('service4')) {
var ths = jQuery(this).find('i').text();
serv4.push(ths);
}
if (jQuery(this).hasClass('service5')) {
var ths = jQuery(this).find('i').text();
serv5.push(ths);
}
if (jQuery(this).hasClass('service6')) {
var ths = jQuery(this).find('i').text();
serv6.push(ths);
}
var ths2 = jQuery(this).find('i').text();
common.push(ths2);
});
common.forEach(function(ele, key) {
comvar += parseInt(ele);
});
comvar2 = comvar / 60;
coml2 = comvar2 / 100 * 1000;
console.log(coml2);
jQuery(this).find('.text-right h2').find('i').text(coml2.toFixed(1).replace(".", ','));
var pars = parseFloat(coml2);
var divd = pars / 100;
var runds = divd * 1000;
var pieces = runds.toFixed(0);
rund = pieces;
//alert(rund);
function addScore(score, $domElement) {
jQuery("<span class='stars-container'>")
.addClass("stars-" + score.toString())
.text("★★★★★")
.appendTo($domElement);
jQuery("head").append(jQuery('<style>.stars-' + rund + ':after { width:' + rund + '%; }</style>'));
}
addScore(rund, jQuery("#fixture-" + m));
});
serv.forEach(function(ele, key) {
a1 += parseInt(ele);
});
sp1 = a1 / szs2;
tot1 = sp1 / 100 * 1000;
serv2.forEach(function(ele, key) {
a2 += parseInt(ele);
});
sp2 = a2 / szs2;
tot2 = sp2 / 100 * 1000;
serv3.forEach(function(ele, key) {
a3 += parseInt(ele);
});
sp3 = a3 / szs2;
tot3 = sp3 / 100 * 1000;
serv4.forEach(function(ele, key) {
a4 += parseInt(ele);
});
sp4 = a4 / szs2;
tot4 = sp4 / 100 * 1000;
serv5.forEach(function(ele, key) {
a5 += parseInt(ele);
});
sp5 = a5 / szs2;
tot5 = sp5 / 100 * 1000;
serv6.forEach(function(ele, key) {
a6 += parseInt(ele);
});
sp6 = a6 / szs2;
tot6 = sp6 / 100 * 1000;
jQuery('.review-block .all-list ul.list-item li').each(function() {
if (jQuery(this).hasClass('service')) {
jQuery(this).find('i').text(tot1.toFixed(1).replace(".", ','));
}
if (jQuery(this).hasClass('service2')) {
jQuery(this).find('i').text(tot2.toFixed(1).replace(".", ','));
}
if (jQuery(this).hasClass('service3')) {
jQuery(this).find('i').text(tot3.toFixed(1).replace(".", ','));
}
if (jQuery(this).hasClass('service4')) {
jQuery(this).find('i').text(tot4.toFixed(1).replace(".", ','));
}
if (jQuery(this).hasClass('service5')) {
jQuery(this).find('i').text(tot5.toFixed(1).replace(".", ','));
}
if (jQuery(this).hasClass('service6')) {
jQuery(this).find('i').text(tot6.toFixed(1).replace(".", ','));
}
})
},
complete: function() {
jQuery('.review-block .all-list ul.list-item li').each(function() {
var ffc = jQuery(this).find('span i').text();
if (jQuery(this).find('span i').text() == "NaN") {
jQuery(this).hide();
}
});
}
});
return false;
});
})
本文标签: How to filter custom post by rating star
版权声明:本文标题:How to filter custom post by rating star 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736293288a1929115.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论