Skip Navigation

[Resolved] Alternative to create custom Gutenberg block

This support ticket is created 3 years, 4 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.

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: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 3 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#2138207

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!! 🙂 )

#2138599

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/

#2142001

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

#2143413

You can follow our document to expose custom fields to WP rest API:
https://toolset.com/documentation/programmer-reference/toolset-integration-with-the-rest-api/