Home › Toolset Professional Support › [Resolved] Conditional display on a custom code snippet you provided for us.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Kolkata (GMT+05:30)
This topic contains 10 replies, has 2 voices.
Last updated by Minesh 11 months, 3 weeks ago.
Assisted by: Minesh.
Previously, you provided us with some custom code to help us organize the results of a view output by date. That code is here:
<?php /** * Snippet to provide sorting and grouping by Date, Session and Round on Results page. */ toolset_snippet_security_check() or die( 'Direct access is not allowed' ); // Put the code of your snippet below this comment. add_filter('wpv_filter_query','func_sort_by_multiple_custom_fields', 199, 3); function func_sort_by_multiple_custom_fields($query_args, $view_settings, $view_id ) { $view_ids = array( 841, 832 ); if( in_array( $view_id, $view_ids)) { $query_args['meta_query'] = array( 'relation' => 'AND', 'match_day_clause' => array( 'key' => 'wpcf-match-date-and-time', 'type'=>'NUMERIC', 'compare' => 'EXISTS', ), 'session_clause' => array( 'key' => 'wpcf-session2', 'compare' => 'EXISTS', ), 'round_clause' => array( 'key' => 'wpcf-round', 'compare' => 'EXISTS', ), 'game_num_clause' => array( 'key' => 'wpcf-game-number', 'type'=>'NUMERIC', 'compare' => 'EXISTS', ), ); $query_args['orderby'] = array( 'match_day_clause'=>'ASC', 'session_clause' => 'ASC', 'round_clause' => 'ASC', 'game_num_clause'=> 'ASC' ); } return $query_args; } add_shortcode('heading', 'my_heading'); function my_heading($atts, $content = '') { static $year = null; static $month = null; static $session = null; static $round = null; static $gamenumber = null; $condition = $atts['condition'];; $value = $atts['value'];; switch ($condition) { case 'year': case 'month': case 'session': case 'round': case 'gamenumber': if ($$condition != $value) { $$condition = $value; return $content; } break; } return ''; }
If you go to this page, you'll see this is working perfectly:
hidden link
Our question now is to see if you can assist us with adding a small bit of code that will make it to where this will only show the results for the current date. We have a large number of matches that were played on January 20th. So to see the schedule for January 21st, everyone will have to scroll down to see those matches. I tried reversing the order but that produced bad results as it showed the 3:00pm matches on top and then went down to the 8:00am matches. We want the entire January 21st date matches to move to the top, but then still have the 8:00am matches display first within that date. I'm not sure how to do that because the match-day-clause grouping done here is set on the full wpcf-match-date-and-time field.
So what I was thinking is we could just add code in here somewhere that will eliminate the display of all results in the view other than ones with the wpcf-match-date-and-time field being TODAY. I tried doing this with a query filter, but it had no effect on the results. I set up
Select items with field:
Match Date and Time is a DATETIME equal to TODAY()
But it still showed both the 20th and 21st on the page. I tried it with conditional output wrapping the loop item and that didn't work either.
Thanks in advance if you can get a fix for us during our overnight hours. It's 9:45pm here now. We're hoping to get a fix for this prior to around 6:00am our time. Sorry for the rush on this. If you are too busy to get to us in time, that's OK. We'll just have whatever fix you provide for the next time.
No worries that nobody is working on tickets today. We'll just have the fix for this on the next tournament.
Hello. Thank you for contacting the Toolset support.
I would like to know do you want to hide those "January 20, 2024" and "January 21, 2024" labels or labels as well as its following sections?
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
The admin access details you shared is not working at this end. Can you please send me working admin access details.
I have set the next reply to private which means only you and I have access to it.
Hold on. I got confused with the replies and I reset the password again when I shouldn't have. Please set up another private reply for me.
I have set the next reply to private which means only you and I have access to it.
Can you please check now: hidden link
Can you confirm this works as expected.
The day order is correct, but that also reversed the time order. That's the problem I couldn't solve and why I started this ticket. We need the time order to stay as it was. We need the days to be descending but the times need to be ascending. I don't know if that is possible or not with the datetime being one field.
So on that schedule page, if it's working as needed, we'd have January 21 on top as it is now, but then the matches within that date would start with the 8:00am matches, then 9:00am matches, etc, etc. to the last matches of that day at 3:00pm (the ones currently displaying at the top).
If having descending dates but ascending times isn't possible, then what we'd want is code that will limit what is shown on this page to a specified date, or to TODAY.. That way while the tournaments are happening only the current day's matches will display when we have that code present. I could add or remove that code as needed manually. The main thing we're trying to do here is to make it to where people don't have to scroll way down the page to see the most recent/current matches. It's not so bad to have to scroll on the Schedule page, but on the Results page it is terrible to have to scroll through all the matches from the previous day to get to the matches from the current day while the tournament is happening. Note that I tried doing that with conditionals and with query filters, but I couldn't get it to work for reasons unknown.
Can you please check now: hidden link
I've added the following filter to sort the data as per your requirement:
- The custom code is added to the "Custom Code" area under "sorting-by-date-session-round-on-results-page" code snippet.
add_filter( 'wpv_filter_query_post_process', 'func_sort_date_schedule_view_post', 999, 3 ); function func_sort_date_schedule_view_post( $query, $view_settings, $view_id ) { if ($view_id == 832) { $sorted_ids = array(); if ( !empty( $query->posts ) ) { $all_posts = $query->posts; foreach($all_posts as $k=>$v): $date_value = types_render_field('match-date-and-time',array('style'=>'text','format'=>'F j, Y','item'=>$v->ID)); $sorted_ids[$date_value][] = $v; endforeach; krsort($sorted_ids); $sorted_posts = array(); foreach($sorted_ids as $k=>$v): foreach($v as $k=>$v): $sorted_posts[] = $v; endforeach; endforeach; $query->posts = array_values($sorted_posts); $query->found_posts = count($sorted_posts); $query->post_count = count($sorted_posts); } } return $query; }
I must say your requirements are fairly complex and needs real attention in order to resolve the issue but really happy to share the solution you aim of.
OK, I see you added this code above the old code in that snippet and kept the old code. It's working perfectly on the Schedule page now. Thanks hugely for that. The only thing left is we also use/need this on the Results page.
I'm seeing in the original code, we had
$view_ids = array( 841, 832 );
But in your new code, it has
if ($view_id == 832) {
I'm not sure of the syntax for making your new code also work on view id 841. Please just get me that and I can add it as needed.
Yeah, I'm finding that the complexity of what's needed to make the life of a pickleball league manager much easier is mind-boggling. All of this is being set up to make things work more smoothly for the manager (my client) while simultaneously being something the tournament participants and their families can view publicly to enhance their experience with the tournaments.
Every time he does another tournament using what's been set up, I tell him to take notes on everything that would make things easier for him. On this particular problem, he was using the Schedule and Results pages to do various things he needed to do and he was finding that he was having to scroll down quite a bit every time he went into those pages to see or do things. I think he was doing everything on his phone, not a desktop or laptop, so the amount of scrolling was that much more and was making the process more painful. Every mouse click or scoll that can be eliminated by streamlining things makes it that much easier for him while he's trying to manage these events in real-time. This small change we've done here will save him several seconds every time he needs to do the things he does from the Schedule and Results pages. That's not such a big deal if he only has to do it once. But when he's doing this dozens of times a day while also simultaneously keeping everything else with the event flowing smoothly and communicating with hundreds of different players on many different teams, saving him those seconds every time is very helpful.
We're gradually improving the system with every tournament and still plan on landing additional organizations to utilize this. The biggest problem we're seeing is that pickleball seems to be a sport with endless complexities to how each tournament is run with regard to match setup and scoring. It's not like every other sport where the rules are pretty much set and nobody deviates from them. I'm finding that the structure of what's needed with pickleball keeps changing with every event run and I'm having to account for so many different possibilities with conditionals that it is very difficult.
The good news there is if this system can be made to work for pickleball with all these complexities we're seeing, it can be made to work for ANY sport. I'm slowly putting together a website to sample this registration/schedule/results/standings system functionality for every major sport. Once it is done, I'll then be able to approach league/organization managers for any sport to demonstrate the capabilities of this. Fingers crossed that the effort there will prove successful.
Thanks for all your help getting this as far as we've gotten with it. I know we're pushing the limits of what's doable within Toolset here. So I hope you're getting good info from this application of things that will help enhance future versions of Toolset.
Can you please check now: hidden link
You spotted the right line of code that you will have to modify but I've adjusted those line of code and the adjusted filter code is as given under:
- The custom code is added to the "Custom Code" area under "sorting-by-date-session-round-on-results-page" code snippet.
add_filter( 'wpv_filter_query_post_process', 'func_sort_date_schedule_view_post', 999, 3 ); function func_sort_date_schedule_view_post( $query, $view_settings, $view_id ) { $view_ids = array( 841, 832 ); if( in_array( $view_id, $view_ids)) { $sorted_ids = array(); if ( !empty( $query->posts ) ) { $all_posts = $query->posts; foreach($all_posts as $k=>$v): $date_value = types_render_field('match-date-and-time',array('style'=>'text','format'=>'F j, Y','item'=>$v->ID)); $sorted_ids[$date_value][] = $v; endforeach; krsort($sorted_ids); $sorted_posts = array(); foreach($sorted_ids as $k=>$v): foreach($v as $k=>$v): $sorted_posts[] = $v; endforeach; endforeach; $query->posts = array_values($sorted_posts); $query->found_posts = count($sorted_posts); $query->post_count = count($sorted_posts); } } return $query; }
Can you please confirm its working as expected now and you are welcome to mark resolve this ticket and let me know your comments.
PERFECT!!! Thanks immensely!