My site has an "exercise" post type. It details how to do an exercise (i.e. a plank, squats, etc). These are like a library.
We will have "S&C Plan" created each week per athlete by a coach. What I want to do is make it nice and easy for the coach to create these by using the Gutenberg editor. In my head I can imagine adding a Custom Block called "Exercise". You then select the exercise you want from the exercise post types listed in a select box. You add reps and sets in two boxes and this outputs into the page neatly, pulling in the featured image, instructions for how to do it etc and linking through to the exercise template for more info.
Is this something you can do with the features in toolset? Or do I actually need to crack how to make Gutenberg blocks (which would need me to learn react, which I really don't like!! 🙂 )
Hello,
Yes, you are right, in order to create such kind of custom WP block, you can check WP document:
https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/writing-your-first-block-type/
In my opinion, you can try these, within Toolset:
1) Create two post types:
- Exercise
- S&C Plan
2) Setup many-to-many relationship between "Exercise" and "S&C Plan", enable the intermediate post type, for example "Exercise-plan" and in intermediate post type, add two custom date fields "Start-datetime" and "End-datetime"
3) In the single "S&C Plan" post, you can:
a) display a Toolset relationship form, for user to connect other "Exercise" posts, and setup the "Start-datetime" and "End-datetime" field values:
https://toolset.com/course-lesson/front-end-relationship-forms-for-connecting-posts/
b) Display a view block:
- Query "Exercise-plan" posts
- Filter by post type relationships between "Exercise" and "S&C Plan"
- In view's loop, display "Start-datetime" and "End-datetime" field values + related "Exercise" posts information
More help:
https://toolset.com/course-lesson/displaying-related-posts/
I'm trying to go down the Gutenberg approach as I don't want to be taking the Coach out of the WordPress admin screens into custom CRED screens. It's already pretty painful building the plans 🙁
So far I've got a block which uses the backbone api to pull in title and excerpt of the custom post type using the Javascript backbone api:
const Exercise = wp.api.models.Post.extend( {
urlRoot: wpApiSettings.root + 'wp/v2/exercise',
defaults: {
type: 'exercise',
},
} );
const Exercises = wp.api.collections.Posts.extend( {
url: wpApiSettings.root + 'wp/v2/exercise',
model: Exercise,
} );
const someExercises = new Exercises();
return someExercises.fetch().then( ( posts ) => {
// do stuff with the exercise
}
Do you know if Toolset custom fields will be exposed via this API? I'm also struggling to get the URL of the featured image as well, which is annoying. I can get it's ID....