Home › Toolset Professional Support › [Resolved] Ideas for approaching creating training plans in a much easier way
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: Africa/Casablanca (GMT+01:00)
Tagged: Toolset Forms, Types plugin
This topic contains 17 replies, has 2 voices.
Last updated by Kelly 3 years, 4 months ago.
Assisted by: Jamal.
Hi! I'm redoing something on my Toolset site which work but are very manually intensive and I'd like to know if there are any suggestions for doing it better.
Right now, I have a series of linked post types which hierarchical for an athletes training plan. Each Athlete has one plan (Macrocycle) which contains multiple training periods (Mesocycles). Each of these contain multiple weeks (Microcycles) and each Microcycle has a number of Sessions within it.
All of this works fine APART from the sessions element as an awful lot of these are identical each week meaning we are filling the database unnecessarily and also it's extremely time consuming to create them each week. (typically you'll make 3-10 of them per athlete each week!)
Also, I'm looking to add Strength and Conditioning (S&C) plans, which would work similarly (a plan would have multiple exercises within them, i.e. planks, lunges etc) but they would suffer from the same problem.
Instead, I'm thinking of replacing Sessions with "Session Templates" (and creating "Exercises") which are commonly used. I.e. for running, a "tempo run session" just explains why we are doing it and what to expect. You'd them pick the sessions templates you want from the library of them when building your Microcycles (and select the exercises for your S&C plan). However, ideally you want to be able to "customise" those templates in some way. I.e. specify "pace and distance" for your tempo run, or number of sets and reps of lunges in that S&C. When you looked at the template, it would be nice to show this.
Is there an obvious way of doing this? Right now you could just associate the templates/exercises to the microcycle but I can't think how you'd be able to display that coherently on the page when the user looks at the microcycle. (I.e. a table with the distance and pace for the tempo run, or the number of sets and reps for the lunges). I could imagine a repeating field where you select the "session" and add the page and intensity but I'm not sure if you can specify another type as a custom field?
Thanks for any suggestions.
Hello and thank you for contacting Toolset support.
First of all, I don't think that creating too many sessions is filling the database unnecessarily, I believe that we should create a post for each session. That way we can link it to its parent Microcycle, and hold different pieces of data(dates, author, etc.).
Keep in mind that a Fields Group is a hidden custom post type. Each item in a field group is actually a separate post, linked to its parent post by a one-to-many relationship.
From what I understand so far, I think that you are looking for a way to duplicate posts easily. I mean, for example, to duplicate the sessions for the next week in an easier way. Currently, Toolset does not offer a built-in duplicate feature. You will need to implement it using Toolset Forms and some custom code, or without custom code at all.
The solution without custom code will consist of having a Toolset Form that should create a new session, with the required fields, and you will pass another post to it as a placeholder. Something like:
[cred_form form="Form to create new session" post="1234"]
Where 1234 is a previous session post that you will use as a placeholder, to pull some data related to the session(title, taxonomy, link to the parent Microcycle, etc.)
I hope this makes sense. Let me know if you have any questions.
I think it makes sense. The challenge I have is the admin is done from the WP admin screens. This means I don't need to recreate all the functionality in CRED screens. The trainer creates the Macrocycle from the WP Admin screen, and within that page, creates the mesocycles using the linked mesocycles section of the admin screen. This carries over the custom field which limits the visibility of it to that specific athlete and their training (via a bit of custom code) and automatically sets up the post relationship. They then click into the Mesocycle, and create the microcycles in there as previously.
This means the most efficient way to create the sessions, is actually from inside the Microcycle edit page! Can Toolset cred forms exist in WordPress admin screens?
I'm happy to custom code, just need to know I'm not going down blind alleys! 😀
Exploring this, I think the easiest way would be for me to have a library of sessions with details already filled out, you then click on a "create session" button, which opens a form. You select a template from the library and add in the additional information required and this is saved as a session. Does that seem possible? This means the trainer doesn't need to fill in the same info every time about how to do the session, and will just repeat this a couple of times from the microcycle page so saving on page loading etc.
I'm very happy to do a screenshare to demo what I've got if that helps get it straight in your head how it's currently working to help btw!
(P.s. support here is great!)
Thank you very much for your kind feedback. I am glad you appreciate it.
Well, for Toolset Forms, they cannot be used inside the WP Admin section. They heavily rely on some core WordPress actions/filters that are fired only on the frontend.
I may say, that anything is probably possible with custom coding. And I would agree that some session templates, with some custom code, can save you time on creating subsequent session posts. However, that would rely entirely on custom code, and frankly, I don't see where Toolset will be used(except for the relationship API to connect posts).
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
Maybe using a duplication plugin can help, but I am sure, you will also need custom code to adapt the new session data(at least dates). You can also check the plugins' code for inspiration:
- https://wordpress.org/plugins/duplicate-wp-page-post/ and the developers' docs hidden link
- https://wordpress.org/plugins/duplicate-post/
Still, if you have any questions, feel free to ask them and we'll do our best to help. In that case, screenshots will for sure help me see the picture clearly.
Just thinking about this, I could probably add a "create session" panel into the Microcycle, which effectively just goes to a front end cred from so can use all the forms functionality.
Are you able to create select boxes filled with other post types with toolset? So I can let the trainer select a template to build use for the session. DO you have any examples of doing this anywhere?
Are you able to create select boxes filled with other post types with toolset?
This is not a built-in feature. But there are three possibilities to do it:
- Using a Post Reference Field.
- Using a Toolset relationship.
- Using an empty select field, with custom code to generate the possible options. The wpt_field_options filter https://toolset.com/documentation/programmer-reference/types-api-filters/#wpt_field_options
Check an example of the filter here https://toolset.com/forums/topic/blank-default-option-in-pre-populated-select-field/#post-1632795
Then, you will have to implement some custom code upon form submission(when the post is created). That way you can pull the template data from the template post and save it for the newly created post.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
You may want to use the cred_success_redirect filter to redirect the user to the newly created post's edit screen, on the WP Admin.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
I've already started with adding a metabox that pulls a list of session templates. My plan is to populate a select dropdown with them and have a "go" button which (hopefully) uses Yoast duplicate page and duplicates it as a different post type using the "duplicate_post_pre_copy" filter.
I had a quick look at wpt_field_options as it looks like a neater way of making the options for the dropdown, but I really don't understand how you use it. Those examples just appear to demonstrate what to put in it, rather than use it. Are there any examples of it in use?
the wpt_field_options is just for populating the options of the field. You need to use them in the cred_save_data action. https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
Depending the field's name, the selected value will be available in the $_POST array:
$template = $_POST['wpcf-template']; // or $template = $_POST['template'];
Then you can use it to get the data from the session template:
$planks = get_post_meta( $template, 'wpcf-planks', true); update_post_meta($post_id, 'wpcf-planks', $planks);
Notice how I add the "wpcf-" prefix to the field's slug. All the fields that are created using Toolset get this prefix saved on their corresponding meta_key at the database level(wp_postmeta table).
You can find various examples of cred_save_data action on the forum with this scoped Google search hidden link
Hello! So, I now have a metabox which lists out "template sessions". When you click on them it uses Yoast Duplicate page to create a "session" with the data from the template. However I ran into an issue in that the copying wasn't able to copy the custom posts fields as they had to have different slugs between the post types.
I got around it by only having one custom field group, but making it available to both session-templates and sessions. This caused another issue though, it didn't like the repeatable field group I had in there. I had to delete it.
Are you able to have a repeatable field group in a set of custom fields which can be used by two different post types? Was the issue that the data in there predated the change?
It is not possible to have a repeatable field group(RFG) for two custom post types. The user interface will display an error and won't let you assign a field group that has an RFG to more than one custom post type. Because RFGs are actually a separate custom post type, rather than a custom field. The RFG post type is linked to the post type using a hidden one-to-many relationship. That's why it can't be assigned to another post type. Especially because each relationship has a unique slug(usually formed by the slugs of the two post types involved on it)
Ah, that's a shame 🙁 Seems like a technical limitation rather than anything that make sense though? Perhaps one for putting on the list of things to add?
Are you able to use the conditional logic to hide certain fields when the custom post group is used on a particular post type? I.e. my session posts have a date (because a session is planned) but the template doesn't because it's use for replication. Similarly, I have a bunch of review fields which only make sense on the session but not on the template type. If not in the UI is there a filter or similar I could use to strip them out from the post edit screen?
Indeed that's a limitation. Especially because relationships need to have unique slugs.
Even if we can't reuse the same Field Group(that includes an RFG) in multiple custom post types. We can use the regular fields. Create another Field Group for the session template post, and reuse the existing fields inside of it. Does it make sense?
This way, you won't need to reuse the "date" field inside the session template's field group, but you can still reuse other fields.
I don't think that will work easily because the other field group has different slugs, so the Duplication won't copy them to the new post type. (Unless you know a better way?)
I wanted to use the RFGs because it allows you to create things like running workouts. I.e. the work out for a long run might be:
Name - Length/Distance - Pace
Long run - 1 hr long - 6:30mins/k
Whereas an intervals session would be:
Name - Length/Distance - Pace
Warm up - 10minutes - 6:30mins/k
Interval One - 5minutes - 3:55mins/k
Recovery - 90 seconds - Easy
Interval Two - 3minutes - 3:30mins/k
Recovery - 90 seconds - Easy
Interval Three - 5minutes - 3:55mins/k
Cool down - 10minutes - Easy.
The RFG is perfect for being able to create this sort of thing as it means the post group data is customisable to the different details of session.
- You can reuse the regular fields, with their slugs. But you can't reuse the RFG.
- You can reuse the regular fields inside and RFG, but again, you can't reuse the same RFG.
- You can assign a Field group to multiple post types. Unless it has an RFG inside of it. In that case, you must create a different Field group, and reuse the fields inside of it. If you need an RFG inside of it, it has to be unique.
These are limitations that we, just, cannot overcome.
I'm not really following that.
However, I've just realised that because you can have multiple post field groups against a post type I can do this:
Session Template AND Sessions have a post field group with:
- Embed field (for video) (repeatable if you have multiple videos)
- Aims (text box)
- Notes (Text box)
- Intensity (select dropdown)
Sessions also have a post field group
- Date
- CRED review form
- RFG for intensities
You set up the Session Template and put loads of detail in the Post Body and the custom fields.
You then duplicate it and the details from the shared post group and post body wll be copies to the Session fro the template. You then add the add the date and RFG details directly on the session and the athlete can complete the CRED when they have done it!
Question: Is there anyway I can move the fields that are currently inside the original post field group to the new shared group?