Skip Navigation

[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.

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, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2611559

Yeah, I can give that a try. Is there any way to easily export Match and Team content from our site to this site? It would be best if I could test using our real data here, but it would take me several hours to rebuild all of that content. If not, then I'd just test using 4 teams and 3 matches for each.

But first, here's another question for you though as I was thinking of another approach to this. Feel free to split this into another ticket if need be. I'm seeing that the limitation here and in the other ticket Luo Yang is working on for us is that there is no way to get the Match scores to associate directly into the correct Team post and the relationship doesn't allow for those scores to be tallied within a Team view display. So now I'm thinking that our score field data has to be saved twice for me to be able to get Standings functionality to work. The scores and Win Loss results must be present as fields in both the Matches content type AND the Teams content type. If I can get that, I think all these dead ends being hit can be worked through.

So my question here now becomes the following: Is there any way for a field in a Post Form for one content type, also save to a corresponding field in another content type? Can it be pushed to save to two locations? Or is there another way to link two fields within two different content types to make them stay the same when one is updated? If it can, then I think that would solve things in an automated way that would be perfect. If it can't, then I think the solution to all of this is that the Team score fields must be manually entered in the same way Match scores have to be added as an additional manual step an admin must take. So on the view I have already set up showing all Teams, I'd need to add an edit link that would lead to an Edit Teams post form, and the admin would have to add match scores there as well after also adding them through the Match post form. That would double the work that the admin has to do manually, but if that's the only way to accomplish the goal, then that's what must be done. Let me get your answer to this question before I try the test platform approach.

#2611565

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Yes, to update the custom field of another post type you can use the Toolset form's hook "cred_save_data". But you make sure that to what specific post you want to update. I hope you build post relationship for that and based on the relationship you will be able to find the related post and update the same value to another post type related post.
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

To apply the same on backend you will have to use the standard "save_post" hook.
=> https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/#an-example

#2611637

Ugh, now I've realized this won't work either, at least not in a way where it can be automated where the admin will only have to enter the match scores once. The reason is because each Team has either 3 or 5 Matches. So the Team 1 Score field and the Team 2 Score field on the Match post form would have to save into different fields on the Team post. For one Match, the score would need to save into a Round 1 Score field. For the next Match for that same team, the score would Need to save into a Round 2 score field and so on. So I couldn't set it to feed to the same field each time. It would need to be conditional, based on the chosen Round. Now I know I'm getting wayyyyy too complex with this request. But if there is a way to do this, definitely let me know.

Just so you understand fully what I mean, here's the relevant details:

On a Match post form, we have fields for Team 1 Men's Doubles score, Team 1 Women's Doubles score, Team 1 Mixed Doubles A score, Team 1 Mixed Doubles B score, Team 2 Men's Doubles score, Team 2 Women's Doubles score, Team 2 Mixed Doubles A score, Team 2 Mixed Doubles B score, Team 1 Result (Win or Loss), Team 2 Result (Win or Loss), Round and the team names are established through two relationships to Teams.

What would be needed with this is to do 5 conditional checks on each field based on the round and then the additional field it should save to in the Team post type would be based on the result of the Round conditional check. So, for example if a Match is in Round 4, we'd have a conditional check saying "If Round is 4, then save Team 1 Men's Doubles score field from the Match post to the Round 4 Team 1 Men's Double's Score field on the Team post that is connected with the relationship established. But if it is in Round 3, there would be another conditional check saying "If Round is 3, then save Team 1 Men's Doubles score field to the Round 3 Team 1 Men's Doubles Score field.

If that's doable, that would allow us to get all Match results into both the Match post AND the related Team post . That would then allow us to build the Standings page in a Team based View and have all needed fields at our disposal and all Match results connected to the Team in a way that Views can use them as needed.

It's good to know that I can do this for other functions though even if it won't work here so thanks for that info.

#2611657

Wait a bit on this latest question about conditionals with this. In my other open ticket with Luo Yang, he brought up a very valid issue with handling these results across multiple years to where pushing this field data from Matches into Teams will be problematic. See the end of this ticket:

https://toolset.com/forums/topic/can-fields-within-a-custom-field-group-get-associated-with-each-other/page/2/#post-2611653

This is getting very complicated for me to wrap my head around everything needing consideration. I may have bitten off more than I can chew trying to get this accomplished. I still want to try though.

Actually, if there is a quick answer you can provide to the question about conditionals, please provide it so I'll have that option available to me should I still want to try it out. But don't invest a lot of time with an answer here because it's now looking like I won't be able to use this approach. I thought I was on a good logical path here, but Luo's point made me realize that it will be too cumbersome to do it this way once we get beyond 3-5 Rounds in one tournament. It's looking like this is going to require a javascript solution along the lines of what he's been showing me and I won't be able to get this as a Toolset only bit of advanced functionality.

#2611671

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

In terms of scalability, I agree yes, you can consider it as lets say for now you have 2-3 rounds and in future you will have 10 rounds at that time what way you will have to go.

That is why its extremely important that you can check first with the test site and see what you can build and whats your requirement and what you can not build and what are the alternate options for features that are not present.

Luo suggested mixing of using data tables (Javascript library) and views but you have to decide with what you want to go as you know the whole project scope and you will have to deal with it in future.

#2611869

That's just it, I'm basically figuring out the project scope as I go along and realizing different things as I try to build it out one step at a time. I know that's not the ideal way to build out something like this, but I'm learning as I go along in hopes of achieving something previously beyond my skill level. When I was on the logic path I was on here in filing this ticket, I was just thinking in terms of getting the current tournament Standings pages set up to match how it is in the spreadsheet file as best I could. I was in tunnel vision mode on that and this approach likely could have worked for that. But then to do the same thing and account for multiple years, tournaments, etc, where there could be MANY more Matches makes this approach too cumbersome to be worth it.

But the goal here was to get it to a point where Toolset only was handling everything with this in hopes of getting a solution where I'd be able to easily duplicate it by doing simple tweaks on everything provided to accomplish everything. When we get into to the javascript solutions, that's beyond my skill level. The custom codes you guys have been providing within Toolset to get this as far as it has gotten so far are ones where I think I'm good enough to tweak those as needed to accomplish the same thing on another site for a different league, at least more often than not.

Is there any other way you can think of to change what's on this page now:

hidden link

To show one team per line and have R1, R2, and R3 results show on that same line?

I think the view has to display Teams, not Matches to do this, but that seems to make getting the scores impossible. I'm having a difficult time wrapping my head around the specific limitation that prevents the relationship between Teams and Matches from allowing this to work. If you go into each Team's edit page, all their Match results are present in there in the Team 1 Matches and Team 2 Matches relationships. I keep thinking there has to be a way to do this within a view.

If you go here and scroll down to see the relationships:

hidden link

You'll see that this team played 5 matches. So for this session that had 5 rounds, I'd have to build out R4 and R5 into this view as well. Three of them are in the Team 1 Matches relationship and two of them are in the Team 2 Matches relationship. So there is a way to tell which scores belong to which team name. This team is Team 1 in all matches in the Team 1 Matches relationship and is Team 2 in all matches in the Team 2 Matches relationship. So there would have to be a way to set up the view to show Team 1 score fields when the Team 1 Matches relationship is used and to show Team 2 score fields when the Team 2 Matches relationship is used. There has to be a way to set that up as a conditional.

Can you help me to understand why this view shows no data in the table when I set it to display Teams instead of matches? I keep thinking if I could just get it to show Teams, the data for the match scores should be able to be pulled through the relationships.

#2611875

Here's what I'd think would display the correct results:

View displaying Teams, table output, with the following TD columns in the loop:

First column would show [types field='team-name'][/types]

That will show all team names in the first column. That's simple.

But then the R1, R2 and R3 columns would have to draw from the relationship and use multiple conditionals. The first conditional would have to check for the Team 1 Matches or Team 2 Matches relationship. The second level of conditional would check the round. On the first conditional, it would determine whether Team 1 or Team 2 score data should be used for the match in that round. On the second conditional it would do a check on the round number to make sure those results only display in the correct round column.

I keep thinking there has to be a way to do this.

#2611947

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Based on your complex structure yes you can use view's inside view.

But first you will have to be sure what way you would like to go.

We can create one view that should query the teams and another view to display related matches where the R1, R2 R3 values are stored.

#2611989

View inside View. View #1 - Show all team names. I've done this and added the session as well so we can have each session grouped the way you helped me do this on the Results page previously. But don't worry about grouping now. I just want to get the tables showing the right things.

hidden link

My new View is called Standings by Round - Teams here:

hidden link

I have this set up to display above the View you created previously on the page. I didn't remove your View because I figure I may need to go back to that one if this effort fails.

So now I need to create another View to display within this View, right?

I have now set up another View called Standings by Round - Matches here:

hidden link

This view is only showing the Men's Doubles match scores for Team 1 and Team 2, but doesn't do anything to try to attach the scores to any team name. And the order on this view does not correlate with the order of the Teams. I'm assuming this Standing by Round - Matches view is going to be included within the other view and that I'll be able to control the display based on the parent Team from the relationship to Match in some way. This Standings by Round - Matches view does include all the conditionals for showing the score in the correct R1, R2, R3, R4, or R5 column. I think that is working correctly here, but I'd have to double check by cross-referencing with the spreadsheet after this is displaying in conjunction with the team names.

This is as far as I can get this and I hope I've done this part correctly. So I need help to now include the Standings by Round - Matches view within the Standings by Round - Teams view and draw on the relationships to display these scores in columns that correlate with and add to the team names.

If we can get this to work, I'm thinking I can account for different tournaments and/or different years through taxonomies on the Teams and Matches content types and query filters based on those taxonomies on the Views. But I realize my thinking may still be misguided here and I may realize a flaw in the logic as I hit another dead end or problem.

New threads created by Luo Yang and linked to this one are listed below:

https://toolset.com/forums/topic/try-to-figure-out-the-best-way-to-account-for-different-tournaments/

#2612109

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

The login access details you shared is automatically removed when you mark resolve the ticket so I do not have it now.

Can you please send me admin access details and let me review this setup now.

I have set the next reply to private which means only you and I have access to it.

#2612599

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I see Luo is working on another ticket - please let me know if I've to work on this further.

#2613417

He's done with that ticket now. That one was to provide the standings based on total points and wins/losses and it looks like all is good there now. I just have to check the math on some discrepancies that are likely problems on our end.

This ticket is for the round-by-round standings which is a separate page. I'm hoping we can get this with a Toolset only solution rather than relying on javascript. The more that is able to be done with Toolset only, the higher the likelihood that this is something I can easily emulate/edit myself going forward.

#2613449

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

To be on the same page you want to display Team name and R1, R2 and R3 in one row - right?

Rather then Team 1 name and Team 2 name and R1, R2, R3 column for both Team 1 and Team 2.

Can you please clarify on table structure how exactly you want to display and I will check what are the possibilities.

#2614497

Yeah, each team on one row with the results from when they are Team 1 and Team 2 combined into that one row.

#2614949

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Before I proceed for any change can you please confirm you want the following columns.

Team name, R1, R2, R3?