Skip Navigation

[Resolved] Need some guidance about how to allow functionality

This support ticket is created 7 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Our next available supporter will start replying to tickets in about 0.70 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#556084

Hi there,

I've gotten quite familiar with Toolset after using it on a few projects, and I'm embarking on a new and perhaps too ambitious project.

I'm attempting to create a site where users can create a FIFA football tournament that other users can join. They will then connect with each other through the FIFA game and input the results at the website and win prices.

So far, so good. I have planned to use Toolset Access to create members areas, and I will create a custom post type for tournaments that users can submit to.

The challenging bit is that each tournament has quite a few variables, that should result in quite different functionality. The tournament craetor should be able to select number of teams, number of members per team (2-11), number of matches between teams and whether the tournament should be played as knockout or league.

The problem with the post type is that it appear to be a display of content, rather than encouraging new behaviour. How would I create a post field for tournaments for "number of teams" that would result in a maximum number of teams that can enter? Or how could a post field that determines the amount of players per team result in a set number of entries?

Am I approaching the issue incorrectly? Could you please share any ideas of how I might solve this issue with Toolset?

Kind Regards,

Andrea

#556198

Hi, I'll do my best to help you figure this out.

How would I create a post field for tournaments for "number of teams" that would result in a maximum number of teams that can enter?
One way to accomplish this is to use a custom field in the Tournament post that determines the maximum number of teams. Your Users can define this value when they create a new Tournament. You will have a post type called "Teams", which will represent each Team. Then you can create a parent / child relationship between Tournaments and Teams. Another name for this is a one-to-many relationship.
https://toolset.com/documentation/user-guides/creating-post-type-relationships/

I assume your users will create Teams using a CRED form. If so you can use conditional HTML to show or hide that CRED form depending on the number of existing child Teams and the custom field value for a Tournament.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

If Teams can play in multiple Tournaments, a one-to-many relationship does not make sense. In this case, you need a many-to-many relationship so you can reuse Teams in multiple Tournaments. Instead of testing the number of Teams in your conditional HTML, you would test the number of intermediary child posts.
https://toolset.com/documentation/toolset-training-course/part-9-many-to-many-relationships-in-toolset/

Or how could a post field that determines the amount of players per team result in a set number of entries?
You can test a custom field's value in a conditional statement that enables or disables a user's ability to create a new post. If the max number of teams has been met, you will hide the form that is used to add new Teams to the Tournament.

Similarly, a conditional statement can be used to display different text to your users like "Add a Team to this Tournament!" or "This Tournament has reached its maximum capacity."

#556517

Hi Christian,

Thank you for the quick feedback, great advice!

You are saying it's possible to make the CRED form for "create team" and "join team" conditional based on how many entries the tournament author decides? How would I create a conditional output depending on the custom field input? Is there any further documentation about conditional outputs?

Assuming I figure out how to set up the leagues, teams and members correctly, do you have an idea for how to solve the fixture generation? If there are 4 teams for example, I wish the site would randomly generate 2 fixtures. I considered using a view for this function, but I believe having a random view means it will change each time a user looks a the page! I need a random fixture that doesn't change, so that all teams gets the same information about who they are about to play.

Again, thanks for the help! Much appreciated!

Andrea

#556982

You are saying it's possible to make the CRED form for "create team" and "join team" conditional based on how many entries the tournament author decides?
I'm saying it's possible to display the form using conditional logic, based on the value of a custom field in the current tournament. The form itself does not include conditional logic. If you are displaying a tournament post, you can access information from a custom field in that tournament post using the [wpv-post-field] shortcode. You can also count the number of child posts in a specific post type. If the number of child posts is less than the custom field number, you will show the CRED form or a link to the cred form. More info below.

How would I create a conditional output depending on the custom field input?
In this example, TournamentTeams is a custom post type used as an intermediary to define a many-to-many relationship between Tournaments and Teams. Therefore TournamentTeams are children of a Tournament in a one-to-many relationship. The general idea is to create a View of TournamentTeams, filtered by post relationship. The parent Tournament should be the current page or post. Inside this View, you can apply a conditional like this:

[wpv-conditional if="( [wpv-found-count] lt [wpv-post-field name='wpcf-num-teams' id='$tournament''])"]
   ... your cred form goes here...
[/wpv-conditional]
<wpv-loop>
   ... you can leave this empty, or add information about each team here. 
</wpv-loop>

Then place this View on the Tournament posts inside a Content Template or Layout for Tournaments. This counts the number of child TournamentTeams and only shows the form if the number is less than the "num-teams" field on the current Tournament.

Is there any further documentation about conditional outputs?
All the documentation I'm aware of is accessible through links on this page:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
If you have specific questions, feel free to open tickets so we can address those for you individually.

do you have an idea for how to solve the fixture generation?
This sounds fairly complex, if I understand you correctly. You would like the system to generate Fixtures, or "matches", automatically, at random, for all TournamentTeams in a Tournament, right? You've got a lot of functionality to figure out here, like what happens for an odd number of Teams, when do the Fixtures get set in relation to the Tournament and Team posts, what happens when a Team drops out before or after the tournament, what happens if no Teams sign up, etc. This is all logic that you would need to figure out and code on your own using PHP.

At the most basic level, you need to be able to create a Fixture post that includes custom fields that define TournamentTeam1 and TournamentTeam2 for this Fixture. You need to be able to determine which TournamentTeams have not been assigned to any Fixtures yet, so you would use wp_query to find that out. Then you can use wp_insert_post to create a Fixture post with the correct meta information.
https://developer.wordpress.org/reference/functions/wp_insert_post/

You need to be able to trigger this Fixture post creation process using certain criteria:
- Trigger it first when the number of TournamentTeams meets the maximum number of Teams allowed by the Tournament, or some other custom criteria you define elsewhere. You can use the save_post hook to check the number of TournamentTeam posts each time a Tournament or TournamentTeam is saved.
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

- Trigger it again repeatedly until all TournamentTeams are included as team1 or team2 custom fields in at least 1 Fixture in this Tournament. What happens with an odd number of Teams, I'm not sure and you would need to work out.

- Possibly trigger it again if Teams drop out or are added later? Up to you.

This is just off the top of my head, but you can see how there is a complex set of functionality to build out, and it's far too much to try to accomplish in one ticket. When the code is directly related to Toolset I can help, but much of this is unrelated to Toolset so you would be on your own. If you have individual questions about specific parts of this process that are related to Toolset, feel free to open tickets and we can try to help.