Sorry about that Minesh!
Price 1665: the date has been changed to 1/3, so it should be displayed instead of the Price 1673 that was dated 27/2. Note that 1665 is actually created before 1673, but i edited the date to a later date.
On the "apply the checking on normal price type", its related to this code. I have a post field price-type that records "normal" or "offer". So i only want the algorithm to work on price-type = "normal", such that if it is an offer price, it will display all; if it is "normal" price, it will display only the latest price for each store (already what the code achieves now).
Thanks!
Minesh
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
Asia/Kolkata (GMT+05:30)
I've adjusted the code as given under:
add_filter( 'wpv_filter_query', 'prefix_show_only_current_author',99,3 );
function prefix_show_only_current_author( $query,$view_settings, $view_id) {
if ( $view_id == 1534 ) { // if
//echo "<pre>";
//print_r($query);
$x = $query['post__in'];
$unique = array();
$tmp_p = '';
$tmp_array = array();
$post_ids = array();
foreach($x as $k=>$v):
$tax = do_shortcode('[wpv-post-taxonomy type="store" format="name" id="'.$v.'"]');
$p = do_shortcode('[types field="price-date" output="raw" id="'.$v.'"][/types]');
$price_type = do_shortcode('[types field="price-type" output="raw" id="'.$v.'"][/types]');
if($price_type=='normal'){
//echo "<br/>tmp==".$tmp_p;
if(!array_key_exists($tax,$tmp_array)){
$unique[$tax]['post_id'] = $v;
$unique[$tax]['tax'] = $tax;
$unique[$tax]['price'] = $p;
$tmp_array[$tax] = $tax;
}else{
if($p > $unique[$tax]['price']){
$unique[$tax]['post_id'] = $v;
$unique[$tax]['price'] = $p;
}
}
}
endforeach;
foreach($unique as $k=>$v):
$post_ids[] = $v['post_id'];
endforeach;
$query['post__in'] = $post_ids;
}
return $query;
}
Is this expected output now? 🙂
Minesh
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
Asia/Kolkata (GMT+05:30)
Is the solution I shared with you help you to resolve your issue? - Could you please confirm.
Thanks Minesh, the logic for "normal" price works fine now even if i edited the date.
But the "not normal" price type is not appearing at all. I think we are missing an "if price type <> normal"?
Thanks a lot.
Minesh
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
Asia/Kolkata (GMT+05:30)
Do you mean that if price type is not normal you still want to display such post without applying the logic we set to compare the date?
That's correct Minesh, it should display as is.
Minesh
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
Asia/Kolkata (GMT+05:30)
Could you please check now. I've adjusted the code as given under:
add_filter( 'wpv_filter_query', 'prefix_show_only_current_author',99,3 );
function prefix_show_only_current_author( $query,$view_settings, $view_id) {
if ( $view_id == 1534 ) { // if
//echo "<pre>";
//print_r($query);
$x = $query['post__in'];
$unique = $tmp_array = $post_ids = array();
$not_normal_ids = array();
foreach($x as $k=>$v):
$tax = do_shortcode('[wpv-post-taxonomy type="store" format="name" id="'.$v.'"]');
$p = do_shortcode('[types field="price-date" output="raw" id="'.$v.'"][/types]');
$price_type = do_shortcode('[types field="price-type" output="raw" id="'.$v.'"][/types]');
if($price_type=='normal'){
if(!array_key_exists($tax,$tmp_array)){
$unique[$tax]['post_id'] = $v;
$unique[$tax]['tax'] = $tax;
$unique[$tax]['price'] = $p;
$tmp_array[$tax] = $tax;
}else{
if($p > $unique[$tax]['price']){
$unique[$tax]['post_id'] = $v;
$unique[$tax]['price'] = $p;
}
}
}else{
$not_normal_ids[] = $v;
}
endforeach;
foreach($unique as $k=>$v):
$post_ids[] = $v['post_id'];
endforeach;
$query['post__in'] = array_merge($post_ids,$not_normal_ids);
}
return $query;
}
And it's displaying all posts now:
=> lien caché
Hi Minesh, i think this is working perfect now. I will replicate and further test on this.
Great thanks for your patience and help!