Home › Toolset Professional Support › [Resolved] Split: Setting up a view with mixed data between two relationships – copy custom fields to another post type post custom field
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.
This topic is split from https://toolset.com/forums/topic/setting-up-a-view-with-mixed-data-between-two-relationships/
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 25 replies, has 2 voices.
Last updated by brettB-4 1 year, 7 months ago.
Assisted by: Minesh.
Yes, but then let me add columns for R4 and R5 myself attempting to emulate what you do after you finish. There was one session that had 5 rounds. I wanted to test first with the 3 rounds and then expand it once it is working.
Again - the admin access details you shared with me previously 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.
I've created the following page:
=> hidden link
I've created the following view that is used to display all teams:
=> hidden link
with the above view's loop output section I've added the another view:
<wpv-loop> <tr> <td>[wpv-post-link]</td> <td>[wpv-view name="standings-by-round-matches"]</td> </tr> </wpv-loop>
To the view "standings-by-round-matches" I've added the following Query filter:
=> hidden link
Filter by post relationship or repeatable fields group owner Select posts in a Team 1 Matches relationship that are a related to the current post in the loop.
Can you please confirm the result you see is correct or you want any modifications.
Sorry for taking awhile to get back to this one. First thing I've done is I added a query filter for the Tournaments taxonomy to your view. That eliminates all the teams that are being set up for our next leagues from this page. The results on this page are now exclusively with the Inaugural Tournament option on that taxonomy. Second thing I've done is I added another query filter for Post Status = publish to cut out the display of any teams that are set to Private.
This looks like it is moving in the right direction. Starting by looking at the first team on the page now, Dinking Friends, the problems with this output are as follows:
1) On that Dinking Friends team the output is showing as being in Round 1, Round 4 and Round 5. In this view:
hidden link
It looks like all 5 rounds should be accounted for already in how it is structured. So I'm not sure why all 5 aren't showing in this output. You can easily see the numbers that should be appearing by looking at the results I now have added to the Team pages. Go here: It looks like the output is only showing when Dinking Friends is Team 1 in the match.
hidden link
For the purposes of this output, you'll only look at the results under the Men column for each match.
2) The results on that team are displaying on three different lines. We're hoping to get them on one line.
3) The results are showing the scores for both teams. On this they should only show the scores for the single team. That what I think the hard part is because sometimes that team will be Team 1 in a match, but other times that team will be Team 2 in another match. There has to be a check in there that will determine if that team name = the team name in the Team 1 relationship then use the score for team 1 in that match, but if that team name = the team name in the Team 2 relationship then use the score for team 2 in that match.
So the output for Dinking Friends here should look like this:
Team Round
R1 R2 R3 R4 R5
Dinking Friends 13 6 21 15 21
The output for Everyrthing, Including does have the first three rounds in the correct place. The ones that are in the second set of R1, R2, R3, R4, and R5 columns are the ones showing Team 2 results in the way I had it originally because I didn't know how to conditionally combine the output based on if the Team Name = the one in the Team 1 relationship or the one in the Team 2 relationship. So that's what is needed to get this part right. This is only showing results if the team name = the team name in the Team 1 relationship. That's why Dinking Friends showed it's output in R1, R4 and R5 because those were the matches where that team = the team name in the Team 1 relationship.
But then I'm still not sure why the results are displaying on three different lines.
The output for this team should be
Team Round
R1 R2 R3 R4 R5
Everyrthing, Including 12 16 10 21 13
You can see that here in the Men column.
hidden link
Note that Wu Wu's Warriors and Bangers and Smash is showing "No items found" as their output. The reason for that is because both of those teams were Team 2 in all of their matches.
hidden link
hidden link
So what I'm seeing again here is it is only showing results when the team is in the Team 1 relationship, not both.
Once all the teams show their correct scores in each round and on one line then the only other things that will be needed are as follows:
1) We need a Total field that will calculate the scores in each round and show that as the last column in the table. I may be able to set this up myself, so don't worry about this yet. Let's just get each round displaying properly first.
2) We need the teams to be sorted and grouped by session and then display within each session with a secondary sort on the Total field. You've helped previously with that kind of grouping by session in another view, so I may be able to copy what you did there and just change fields as needed, but I'll likely need some help with that. Understood if that will have to be broken into another ticket.
I know this is absurdly complicated and I apologize for that. I just know that if we can succeed at this for the way this one is set up, I'm confident in having success with this for ANY sports league. I don't think there will be many or any sports with a standings/results system as complicated as this.
The spacing in how I tried to show the desired output didn't show the same way as it was where I composed the message. Let me know if you know what I meant there or if I should try again with HTML to show it.
Here is the result now: hidden link
With the parent view I'm passing the team id as shortcode attribute teamid="[wpv-post-id]":
=> hidden link
<wpv-loop> <tr> <td>[wpv-post-link]</td> <td>[wpv-view name="standings-by-round-matches" teamid="[wpv-post-id]"]</td> </tr> </wpv-loop>
And with the nested view "standings-by-round-matches", I've adjusted the "Query filter" as given under:
Filter by post relationship or repeatable fields group owner
Select posts in Any relationship that are a related to the current post in the loop.
=> hidden link
I've adjusted the output of the above view as given under for Loop editor:
[wpv-layout-start] [wpv-items-found] <!-- wpv-loop-start --> <table width="100%"> <tbody class="wpv-loop js-wpv-loop"> <tr> <th>R1</th> <th>R2</th> <th>R3</th> <th>R4</th> <th>R5</th> </tr> <tr> <wpv-loop> [wpv-post-body view_template="loop-item-in-standings-by-round-matches"] </wpv-loop> </tr> </tbody> </table> <!-- wpv-loop-end --> [/wpv-items-found] [wpv-no-items-found] <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong> [/wpv-no-items-found] [wpv-layout-end]
And for template for this view section as given under where I'm catching the value of shortcode attribute teamid using the shortcode: [wpv-attribute name='teamid'] and checking with the conditional statement that if the temid attribute value equal to the current match's parent team ID then we will display team 1 otherwise the value will be displayed from team 2.:
[wpv-conditional if="( $(wpcf-round) eq 'Round 1' )"] <td> [wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"] [types field="team-1-score-mens-doubles"][/types] [/wpv-conditional] [wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"] [types field="team-2-score-mens-doubles"][/types] [/wpv-conditional] </td> [/wpv-conditional] [wpv-conditional if="( $(wpcf-round) eq 'Round 2' )"] <td> [wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"] [types field="team-1-score-mens-doubles"][/types] [/wpv-conditional] [wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"] [types field="team-2-score-mens-doubles"][/types] [/wpv-conditional] </td> [/wpv-conditional] [wpv-conditional if="( $(wpcf-round) eq 'Round 3' )"] <td> [wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"] [types field="team-1-score-mens-doubles"][/types] [/wpv-conditional] [wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"] [types field="team-2-score-mens-doubles"][/types] [/wpv-conditional] </td> [/wpv-conditional] [wpv-conditional if="( $(wpcf-round) eq 'Round 4' )"] <td> [wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"] [types field="team-1-score-mens-doubles"][/types] [/wpv-conditional] [wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"] [types field="team-2-score-mens-doubles"][/types] [/wpv-conditional] </td> [/wpv-conditional] [wpv-conditional if="( $(wpcf-round) eq 'Round 5' )"] <td> [wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"] [types field="team-1-score-mens-doubles"][/types] [/wpv-conditional] [wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"] [types field="team-2-score-mens-doubles"][/types] [/wpv-conditional] </td> [/wpv-conditional]
Can you please confirm it works as expected now.
YEAH! This is perfect at least for the issues of getting everything on one line and displaying the correct scores for each round checking if the score in that round should come from Team 1 or Team 2.
Now I'm trying to add a calculating total field. I already have this site set up to do calculations using custom code I found in another support thread, so it should work. But the problem is to get the correct scores to use for each round, I'd have to duplicate all your code using many conditionals.
Here's the code I'm using on the results view to display the totals there that are applying to match scores::
<div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px; margin-left: 5px;">[wpv-calculate][types field="team-1-score-mens-doubles"][/types]+[types field="team-1-score-womens-doubles"][/types]+[types field="team-1-score-mixed-doubles-1"][/types]+[types field="team-1-score-mixed-doubles-2"][/types] [/wpv-calculate]</div>
I know that's not what is needed here. I'm just showing you how that calculation is done in that view.
So here, I'd need to add all your conditionals within conditionals to first check for the round number, then if team one or team two should be used and then have the + operator between each. That should be doable.
But I was wondering if there is an easier way. Is there a way to add hidden code that would assign the correct value to new variables? For example: we could define variables with the names rbr-mens-doubles-round-1, rbr-mens-doubles-round-2, rbr-mens-doubles-round-3, rbr-mens-doubles-round-4, and rbr-mens-doubles-round-5. And then within the loop, add some code that doesn't get displayed that will pass the numerical value that actually gets displayed after all your conditionals are gone through for each round to the new variable name. Is that possible?
If that's possible, then to get the correct calculation, the code for that Total column could just be some form of:
<div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px; margin-left: 5px;">[wpv-calculate]rbr-mens-doubles-round-1+rbr-mens-doubles-round-2+rbr-mens-doubles-round-3+rbr-mens-doubles-round-4+rbr-mens-doubles-round-5[/wpv-calculate]</div>
without having to redo all the different conditionals. I'm sure my syntax is wrong for how to use these new variables in there though, but I'm sure you get the idea I'm trying to convey with that.
If that isn't doable, then let me go ahead and try to add this total field myself using all your conditionals to get the values again. Just let me know on this inquiry before I do that.
I've added another column to your output in this view:
hidden link
I just did a calculation on 1+1+1+1+1 just to have something to populate that total column for each team now until you let me know about the inquiry above. Adding this has produced mixed results for me on the page here:
hidden link
For some of the teams it did exactly what I was trying to do. But for others it is inexplicably showing additional columns after the total column. I'm trying to do what I can here, but I'm afraid I'm just not very good at this.
Oh wait, now I see why it did that. We currently have R4 and R5 set to display as column headers in all cases, even where there are no R4 or R5 matches. But then your conditionals setup only displays the cell where the scores go IF there is a score to add. Otherwise no cell gets added to that row. So on the header row, we automatically have 5 across, but on the teams with only 3 rounds, they only have 3 across on the scores row. So the rows get mismatched. So I think what's needed to get this right is to set up the display of the R4 and R5 cells on the header row to be conditional on if these fields are not empty. I just tried to do that myself, but I didn't get the output I was hoping for. I think that's because the table header column is displayed outside the loop, so the conditionals doing field data checks aren't working there. If I'm right on that, I'm not sure if it will be possible to do what's needed there the way I'm thinking.
Basically with this we need teams that have 5 rounds to display a table that has 5 round columns and then the total field and teams that have 3 rounds to display a table that has 3 round columns only and then the total field. The R4 and R5 table headers should only display if there are 5 rounds to show for that team. Is there any way to achieve that here? I think once that is done, my total column will line up correctly for all teams, but then I have to figure out how best to get the correct totals to appear. Ideally, the number of R columns would be determined based on how many rounds each team has. That way we won't be limited to only using 3 or 5 here. If we subsequently have a tournament where there are 7 rounds, the view would account for that possibility as well. Can that happen or is that too much? Regardless of this, I think we just need the number of cells in the header row to always match the number of cells in the score row. That way the subsequent Total column will line up in the right place.
You should try to apply the total as you know.
If you will require further help, please feel free to create a new ticket and link the old ticket for reference and I would be happy to help.
OK, I tried that and it didn't work either. The code I added to the loop to create this Total column is as follows:
<td>[wpv-calculate][wpv-conditional if="( $(wpcf-round) eq 'Round 1' )"][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"][types field="team-1-score-mens-doubles"][/types][/wpv-conditional][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"][types field="team-2-score-mens-doubles"][/types][/wpv-conditional][/wpv-conditional]+[wpv-conditional if="( $(wpcf-round) eq 'Round 2' )"][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"][types field="team-1-score-mens-doubles"][/types][/wpv-conditional][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"][types field="team-2-score-mens-doubles"][/types][/wpv-conditional][/wpv-conditional][/wpv-calculate]+[wpv-conditional if="( $(wpcf-round) eq 'Round 3' )"][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"][types field="team-1-score-mens-doubles"][/types][/wpv-conditional][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"][types field="team-2-score-mens-doubles"][/types][/wpv-conditional][/wpv-conditional]+[wpv-conditional if="( $(wpcf-round) eq 'Round 4' )"][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"][types field="team-1-score-mens-doubles"][/types][/wpv-conditional][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"][types field="team-2-score-mens-doubles"][/types][/wpv-conditional][/wpv-conditional]+[wpv-conditional if="( $(wpcf-round) eq 'Round 5' )"][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-1-match.parent']' )"][types field="team-1-score-mens-doubles"][/types][/wpv-conditional][wpv-conditional if="( [wpv-attribute name='teamid'] eq '[wpv-post-id item='@team-2-match.parent']' )"][types field="team-2-score-mens-doubles"][/types][/wpv-conditional][/wpv-conditional][/wpv-calculate]</td>
I just copied and pasted all the conditional code you set up to get the correct score for each team in each round and added + between them to do the calculation. I also removed all the spacing/line breaks because I feared that would interfere with the calculation functionality in some way. So I have all of this as one continual line. I'm sure there's a syntax problem in there somewhere. The result of adding this code causes the view output to completely white screen. Nothing shows on the page with this added, not even the stuff you had working before. So I removed this code on the view right now. I'll see what you have to say about this before trying to add anything different.
Here is the code snippet provided to us in another support thread for doing the calculations:
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
add_shortcode('wpv-calculate', 'calculate_shortcode');
function calculate_shortcode($atts,$content=null) {
$content = wpv_do_shortcode($content);
$content = eval("return $content;");
return round($content);
}
This code works perfectly with the calculations we've already set up. I'm guessing something with all the conditionals present in my attempt above is causing this to fail.
New threads created by Minesh and linked to this one are listed below:
Ok.
As per our support policy, we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery for the issue initially reported with this ticket.
May I kindly ask you to open a new ticket with every new question you may have with new ticket.
I'll split ticket here with your new question and you are welcome to mark resolve this ticket.
=> https://toolset.com/forums/topic/split-split-setting-up-a-view-with-mixed-data-between-two-relationships-copy-custom-fields-to-another-post-type-post-custom-field-add-total-column/
My issue is resolved now. Thank you!
I put this as very hard to solve, but I want to make sure that doesn't reflect negatively on your help in any way. If it does, then please bring it to the attention of whoever needs to see it that I'm ECSTATIC with your level of support. This is just a VERY difficult thing I'm trying to get accomplished. I wanted to make sure to say that here. There is no way in the world we'd be able to get 1/10th as far as we have without your willingness to assist. Whatever would serve you best as an endorsement, I think any of my clients would be willing to do for you. If you want to show off any of this functionality as examples of things that can be achieved, definitely let me know.