Home › Toolset Professional Support › [Resolved] Can fields within a custom field group get associated with each other ?
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 |
---|---|---|---|---|---|---|
- | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9: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/Hong_Kong (GMT+08:00)
This topic contains 27 replies, has 3 voices.
Last updated by brettB-4 1 year, 7 months ago.
Assisted by: Luo Yang.
The math is all correct. I found two discrepancies between the totals on the page and the totals on the spreadsheet. One of those was my fault with a brain glitch in migrating one score. One of those was a problem with the score shown in the round by round section of the spreadsheet. So those were both on our end.
This fully works. So just let me know if there's any way to get these numbers to save to the appropriate fields within each team page and if we can sort the results on the Total Points field in descending order. This is FANTASTIC!!!
There isn't such kind of built-in feature within Toolset plugins, Toolset plugins can display post data, but can not calculate the values.
And it is not a good idea to store those numbers into custom fields, if you save those values, the "Filter by Session" won't work as expected, since you are save all Session numbers, after even filter the result by one Session, it still displays all Session numbers.
As a workaround, you can sort the HTML table with custom JS codes, please confirm it before we proceed, and I will create another ticket for it.
I've set up the shortcode for calculating values already. That's how I got the total points field on the view I set up. I found an older support thread covering that and tried it and I got it to work. I set the view to show the result of adding all four game scores together in that column of the table.
The thing is if we're able to save those values to the Team fields, then I'll be able to create new views showing that information however I'd like it and I'll be able to experiment with it. But if it is done with the javascript, I'll have to ask you for help with each change. I hate having to ask for so much assistance, but I'm limited in what I can do here. I'm good enough at what I'd term a high school level of Toolset setup, having learned enough through all the support tickets you guys have helped me with across multiple client's sites, to be able to meet a lot of client needs myself. But it seems like every time I need something different or more advanced, I end up hitting a dead end with my effort and I have to come back for more help. I hate having to bother you for so much assistance with this.
However you'd prefer to do it is fine. So feel free to split this ticket. The remaining things I'd like to do on this page are as follows with grouping/sorting:
1) Group the results by session. Minesh helped us with grouping and sorting on the Results page I previously set up here:
hidden link
Here is the custom code he provided for this:
hidden link
See sorting-by-date-session-round-on-results-page
This sorts/groups by date as the primary sort, session as a secondary sort , round as a third level sort and game number as the final sort. This was needed because Toolset didn't have anything to do multiple levels of sorting on custom fields. All sessions appear sorted alphabetically under a single date header. All rounds appear alphabetically under a single session header. All game numbers appear alphabetically under a single round header.
The way we'd like to do it on this page is simpler:
On this page, we'd just need a session header and then the table of results for just that session. So the teams would be grouped under their session. I set up a filter to allow the end user to choose the session they want to see, but I thought about that and decided it would be better to show ALL standings with no filter but to have them grouped by session in how they display. If not having that filter present on this page makes it to where saving the fields can work, then that would be even better for that as well. But grouping the results by session would be the same thing as how sports leagues with conferences and divisions display their standings. I think that's the way to go here, not the filter approach. We're hoping to get something that can be used by any sports league.
2) Then it would have a secondary numerical sort for Total Points to display in descending order. So if there are four teams in each session then the results under that session would show a table of four sorted from the highest point total to the lowest point total. We have mostly four teams per session, but there is one session with six teams.
If the data from this view you've set up could be pushed to the fields within Teams, then I think I might be able to set up this view myself, or it least get it most of the way there. But with your javascript code, I'm entirely dependent on what you're able/willing to do for us and I constantly feel like I'm taking advantage of your generosity.
Lastly I need to ask if the view you set up is dependent on the view I set up also being present on the page. We'd like the Standings page to ONLY have the view you set up, but I'm not sure if the javascript you created depends on the data from my view being displayed on the page. If your view depends on my view being present, then how can we hide my view from display and still allow your view access to the data?
I'm seeing now that your view is dependent on my view being on the page. I wrapped my view in a div with display: none; as a style and that worked to remove my view from display on the page while still allowing your view to show with correct results. So that part of the issue is resolved now.
I've added another column to your view to show the Session and I have the primary sort on it set to use Session ascending. I also removed the Session filter.
hidden link
This gets things a little bit closer to exactly how we'd like it to be. But for this to be perfect, the way this should display now is as follows:
1) Each Session would have its own header showing the session name
2) Each Session would have its own table under that header
3) The secondary sort would be on Total Points descending
So with our existing data, we'd have the first two sessions show as:
Session - Afternoon - 3.0
Team Total Points Wins Losses
SWAT 248 3 0
Everlasting Lobstoppers 230 2 1
We Don’t Dink Alone 215 1 2
Bangers and Smash 173 0 3
Session - Afternoon 3.5
Big Dill Picklers 247 3 0
Day Dinkers – Render 3.5 240 2 1
Canton Pickle Smack 207 0 3
Augusta Dinking Buddies 188 1 2
and so on for all remaining sessions.
Is this doable? This should work using an altered version of the grouping/sorting code Minesh did for us on the other view.
I've duplicated the grouping/sorting code that Minesh provided to try to get this to work myself. His code is in the
sorting-by-date-session-round-on-results-page
snippet on
hidden link
I've now added another snippet called
sorting-by-session-total-points-on-standings-page
In that, I left his sort on the Session field. I changed the session field key from session2 to session. Session2 is the field within the Match content type, while session is the one in Team. We're showing Teams in this view so I thought that change was needed. I removed all the other field sorting/grouping because those are not ones that are needed here. I'm uncertain how to add a sort within that snippet on this total points number, because that's being generated through your javascript. I can't just change the field name in his code from one of the other sorts and have it work. So I've gotten it as far as I can here.
Oops, I just noticed I was logged in with the wrong user account on the previous two posts. I'm handling setup work for multiple sites using Toolset. The last two posts from lesleeM should have been from brettB-4
Yes, they doable with custom codes, for example, you can sort the results with custom JS codes:
hidden link
See the demo in above document
If you need assistance to setup the custom JS codes, you can just update this ticket, I can split another ticket, and setup a demo in your website.
I tried the demo at the link you provided, but that doesn't look like what's needed. That does allow sorts on multiple headers, and multiple levels of sorts, but it forces the end user to click the header to see the sort done on that header. We're not wanting this to be something where the end user controls the sort. We only want it sorted the one way by default and with no control for the end user to change the sort. It is possible that I missed something in the demo that would do it exactly as we want it though.
The first sort should be by Session, which is already working. That sort should also provide a grouping to where only items within each session appear under that Session header. Then within each individual Session table, those entries should have a secondary sort done on the Total Points field so they will display in highest score to lowest score order.
If this demo you've provided CAN do it this way or not, you're WAYYYY beyond my skill level here either way, so we'd definitely need as much help as you're willing to provide on this. That's why I was hoping to get the data fed into the fields within the Team content type for each team. If the data can somehow be fed into there, then we'd bring it back to something within my skill level to try to do things with using Toolset Views.
Understood fully if this is something where we'd need to get a contractor to complete this, but we'd VERY MUCH prefer to pay YOU to get it done if we have to go that route. I had a VERY negative experience with one of your listed contractors hired by one of my other clients.
I still don't recommend you to store those "Total Points" and "Wins" and "Losses" values into custom fields, this will conducts unexpected results in the feature.
For example, those values are update with team's lifetime, if you want to filter the results by match time within 2023 year, then it will be a problem.
As I suggest you:
- Use first hidden post view to query match's you want to count and sum the result
- Use the second post view to query team's you want to display
- Use custom JS codes to count and sum the result values from first post view, and display them in second post view.
And yes, it is possible to sort the results by Session-> Total Points field by default with custom JS codes, see their demo:
hidden link
In order to upload the "tablesorter" JS/CSS files into your website, please provide FTP/SFTP access of your website in below private message box, I can setup a demo for you. Private message box enabled.
Since you did not provide the FTP password, I can not upload "tablesorter" JS/CSS files into your website, so I setup the demo with jsdelivr CDN links:
hidden link
Here are detail steps:
Edit the team post view "Teams posts":
hidden link
1) in section "Search and Pagination", load the "tablesorter" JS/CSS files:
<script src=" <em><u>hidden link</u></em> "></script> <link href=" <em><u>hidden link</u></em> " rel="stylesheet">
2) In section "Loop Editor", change line 4 to:
<table width="100%" class="tablesorter" id="myTable">
3) in section "JS editor", setup the JS codes as below:
jQuery( document ).ready(function($) { $('.total-score').each(function( index ) { var teamID = $(this).attr('team-id'); var totalScore = 0; $( ".score-" + teamID ).each( function(){ totalScore += parseFloat($(this).text()); }); $(this).text(totalScore); }); $('.total-win').each(function( index ) { var teamID = $(this).attr('team-id'); var totalWin = $( ".Win.result-" + teamID ).length; $(this).text(totalWin); }); $('.total-loss').each(function( index ) { var teamID = $(this).attr('team-id'); var totalLoss = $( ".Loss.result-" + teamID ).length; $(this).text(totalLoss); }); //tablesorter $(function() { $("#myTable").tablesorter({ sortList: [[0,0], [2,1], [3,1]] }); }); });
Line 23~25 will be able to sort the results in below orders:
Session(ASC)-> Total Points(DESC)-> Wins(DESC)
Test it in frontend:
hidden link
It works fine.
More helps:
hidden link
sortList: Use to add an initial sort to the table.
I thought I did provide the password. I can send it. I might have forgotten to paste it thinking I did paste it.
I followed your instructions and it is working to sort the points field in descending order, so all good there. Thanks yet again! Let me know what's needed to have it operate internally with the files on our server.
For this page to be perfect, we just need to separate and group the sessions. See this page for what I mean there:
hidden link
The custom code Minesh provided to accomplish this is below:
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 ); 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'=>'DESC', '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 ''; }
But I wouldn't know how to achieve the same result with what's being created by your javascript. The only level we need grouped here is Session where he set this up for date, session, round and game number, and it would use the wpcf-session field, not wpcf-session2 because this view is showing Teams not Matches.
We are preparing for the next tournament on this site. That tournament will happen on June 24th. So I will have a whole different set of teams and matches that I'll enter into the system in the leadup to that tournament and then I'll add all the match scores after June 24th. Once those are set up, I'll try to figure out the best way to account for different tournaments in the structure of everything that is already working (Teams, Schedule, Results). If we get that working for different tournaments, the same approach could be used for different years as well.
There is no rush to have this all working before this June 24th tournament. We're just using the real life team and match information to provide the testing environment to account for all needs with this. Whenever this is all operational, I'll then add it to the site on pages accessible through the top menu, but there is no pressure as to when it all actually works. This is just something I'm trying to get if it can be done because I see the potential to market this functionality to leagues like this anywhere in the world. I decided to see how much of this Toolset would be able to accomplish, but I knew the Standings functionality was going to be the most difficult to achieve and would push Toolset capabilities. Sorry that this is proving this difficult to achieve everything and sorry there are so many details to keep straight and account for with this. This specific league's scoring/standings approach is probably as complex as any sports league would ever be. So this is actually good to see if it can be done with this, while being more difficult. If it can be done with this, I think it can be done for any other sport much more easily.
According to our support policy, we prefer to one ticket one question, for other new questions, please check the new ticket here:
https://toolset.com/forums/topic/try-to-figure-out-the-best-way-to-account-for-different-tournaments/
You can close this one, and follow above new ticket.
THANKS YET AGAIN!!!