Skip Navigation

[Resolved] Create a new post as a clone of an existing post

This thread is resolved. Here is a description of the problem and solution.

Problem:

Setup a student lessons website?

Solution:

Multiple students can have same lesson, so you can try these:

https://toolset.com/forums/topic/create-a-new-post-as-a-clone-of-an-existing-post/#post-2369193

Relevant Documentation:

This support ticket is created 2 years, 6 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 10 replies, has 2 voices.

Last updated by Doug Watt 2 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#2357481
Screenshot 2022-05-07 140730.jpg

Tell us what you are trying to do?

The site was build for a music teacher. The notes for each lesson are saved as a post. When a student arrives for their next lesson, the teacher would be like to be able to create a new post which would carry across all of the notes from the students most recent lesson.

I imagine it could work by having a link right next to the current "Edit" link which would open a clone of the current post rather than simply edit the current post.

It would work just as well to create a new post; enter a title; the current date and select the student from a dropdown and then have the post auto-populated with the data from the selected students most recent lesson post.

Is any of this possible?

Many thanks,

Doug
====

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
hidden link

#2358729

Hello,

There isn't such kind of built-in feature within Toolset plugins, you might consider custom codes, for example:
1) Create a custom shortcode with a custom PHP function:
https://developer.wordpress.org/reference/functions/add_shortcode/

2) In this custom PHP function, get the data from the selected students most recent lesson post

3) Then use it as default value of form field:
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_field
value. Optional. Preset value

#2358791

Many thanks for your reply.

I think I know what you are suggesting, but I've never done that before. I'm very willing to give it a go. Are you able to give me any more detail to get me started?

Thanks,

Doug
====

#2359557

How do you define the relationship "selected students most recent lesson post"?
You can follow WordPress document to query post:
https://developer.wordpress.org/reference/classes/wp_query/
If there is Toolset post type relationship, you can follow our document to add post type relationship filter into the query:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#new-approach
section "NEW APPROACH"

#2360021

How do you define the relationship "selected students most recent lesson post"?

I'm thinking that the teacher would simply open the student's most recent post as the starting point of the process.

From the front-end of the site what I'd like to achieve is the same as we can easily do at the back-end thru use of a post duplicating plugin, ie create a duplicate post which could then be renamed and saved.

#2360269

Maybe my question is not clear.

How do you setup the post types?
How do you setup the post type relationship?
How do you setup the post form?
Which post of post type do you want to duplicate?

Please provide detail steps to reproduce the same problem, thanks

#2365561

Understood.

I'll put together a video. I'm replying like this now simply to keep the post open until I get the video done.

#2365579

Here's a video to explain what I am trying to do. I trust that it will answer your questions.
Many thanks for your help.

hidden link

#2366175

I forgot to answer your question about "how did I create the form?"

Both the Create Form and the Edit form are CREDFORM. Here's the code for the create form.

[credform]
<div class="container-fluid" style="background-color:#e8e8e8;">
<div class="row">
<div class="col-md-12">
[cred_field field='form_messages' class='alert alert-warning']
</div>
</div>
<div class="row" style="background-color:#EFF1DB; border:1px solid black;">
<div class="form-group col-md-4">
<label class="main-label">[cred_i18n name='post_title-label']Lesson Title[/cred_i18n]</label>
<p>Type a lesson title here. It's not critical, but will appear as the title of the lesson in the lesson archives.</p>
[cred_field field='post_title' class='form-control' output='bootstrap']
</div>
<div class="form-group col-md-4">
<label class="main-label">[cred_i18n name='post_title-label']Lesson Date[/cred_i18n]</label>
<p>Select the date of the Lesson - may be different than the date on which the post is created. </p>
[cred_field field='lesson-date' force_type='field' class='form-control' output='bootstrap' value='[today]']
</div>
<div class="form-group col-md-4">
<label class="main-label">[cred_i18n name='@student-lesson.parent-label']Student[/cred_i18n]</label>
<p>Only the last 10 students to be entered into the system show in the dropdown. For others, type at least 3 letters of their name and they will appear.</p>
[cred_field field='@student-lesson.parent' class='form-control' output='bootstrap' select_text='-- select student from this dropdown --' required='false']
</div>
</div>
<div class="row" style="background-color:#FFD4DB; border:1px solid black;">
<div class="form-group col-md-12">
<label class="main-label">[cred_i18n name='this-week-label']This Week[/cred_i18n]</label>
<p>Use the WYSWYG editor to write comments about This Week. The "Add Media" facility can be used to add media files including mp3's, videos (mp4's and YouTube links), as well as any PDF's. These will all display as active links.</p>
[cred_field field='this-week' force_type='field' class='form-control' output='bootstrap']
</div>
</div>
<div class="row" style="background-color:#D3B5E5; border:1px solid black;">
<div class="form-group col-md-6">
<label class="main-label">[cred_i18n name='song-craft-label']Song Craft[/cred_i18n]</label>
<p>Use the WYSWYG editor to write comments about Song Craft. The "Add Media" facility can be used to add media files including mp3's, videos (mp4's and YouTube links), as well as any PDF's. These will all display as active links.</p>
[cred_field field='song-craft' force_type='field' class='form-control' output='bootstrap']
</div>
<div class="form-group col-md-6">
<label class="main-label">[cred_i18n name='song-craft-images-label']Song Craft Images[/cred_i18n]</label>
<p>Use this upload facility to include up to three images. They can be selected at the same time, or individually. They will display as a block of three thumbnail images and will open in a lightbox when clicked.</p>
[cred_field field='song-craft-images' force_type='field' output='bootstrap' previewsize='thumbnail']
</div>
</div>
<div class="row" style="background-color:#BBE7FE; border:1px solid black;">
<div class="form-group col-md-6">
<label class="main-label">[cred_i18n name='music-craft-label']Music Craft[/cred_i18n]</label>
<p>Use the WYSWYG editor to write comments about Music Craft. The "Add Media" facility can be used to add media files including mp3's, videos (mp4's and YouTube links), as well as any PDF's. These will all display as active links.</p>
[cred_field field='music-craft' force_type='field' class='form-control' output='bootstrap']
</div>
<div class="form-group col-md-6">
<label class="main-label">[cred_i18n name='music-craft-images-label']Music Craft Images[/cred_i18n]</label>
<p>Use this upload facility to include up to three images. They can be selected at the same time, or individually. They will display as a block of three thumbnail images and will open in a lightbox when clicked.</p>
[cred_field field='music-craft-images' force_type='field' output='bootstrap' previewsize='thumbnail']
</div>
</div>
<div class="row" style="background-color:#ECE3F0; border:1px solid black;">
<div class="form-group col-md-6">
<label class="main-label">[cred_i18n name='key-craft-label']Key Craft[/cred_i18n]</label>
<p>Use the WYSWYG editor to write comments about Key Craft. The "Add Media" facility can be used to add media files including mp3's, videos (mp4's and YouTube links), as well as any PDF's. These will all display as active links.</p>
[cred_field field='key-craft' force_type='field' class='form-control' output='bootstrap']
</div>
<div class="form-group col-md-6">
<label class="main-label">[cred_i18n name='key-craft-images-label']Key Craft Images[/cred_i18n]</label>
<p>Use this upload facility to include up to three images. They can be selected at the same time, or individually. They will display as a block of three thumbnail images and will open in a lightbox when clicked.</p>
[cred_field field='key-craft-images' force_type='field' output='bootstrap' previewsize='thumbnail']
</div>
</div>
<div class="row" style="background-color:#F8C0C8; border:1px solid black;">
<div class="form-group col-md-6">
<label class="main-label">[cred_i18n name='piece-craft-label']Piece Craft[/cred_i18n]</label>
<p>Use the WYSWYG editor to write comments about Piece Craft. The "Add Media" facility can be used to add media files including mp3's, videos (mp4's and YouTube links), as well as any PDF's. These will all display as active links.</p>
[cred_field field='piece-craft' force_type='field' class='form-control' output='bootstrap']
</div>
<div class="form-group col-md-6">
<label class="main-label">[cred_i18n name='piece-craft-images-label']Piece Craft Images[/cred_i18n]</label>
<p>Use this upload facility to include up to three images. They can be selected at the same time, or individually. They will display as a block of three thumbnail images and will open in a lightbox when clicked.</p>
[cred_field field='piece-craft-images' force_type='field' output='bootstrap' previewsize='thumbnail']
</div>
</div>
<div class="row" style="background-color:#EFE7D3; border:1px solid black;">
<div class="form-group col-md-4">
<label class="main-label">[cred_i18n name='library-label']Library[/cred_i18n]</label>
<p>Use the WYSWYG editor to write comments about the Library. The "Add Media" facility can be used to add media files including mp3's, videos (mp4's and YouTube links). These will all display as active links.</p>
[cred_field field='library' force_type='field' class='form-control' output='bootstrap']
</div>
<div class="form-group col-md-4">
<label class="main-label">[cred_i18n name='library-label']Library Images[/cred_i18n]</label>
<p>Use this upload facility to include up to three images. They can be selected at the same time, or individually. They will display as a block of three thumbnail images and will open in a lightbox when clicked.</p>
[cred_field field='library-images' force_type='field' output='bootstrap' previewsize='thumbnail']
</div>
<div class="form-group col-md-4">
<label class="main-label">[cred_i18n name='library-books-label']Library Books[/cred_i18n]</label>
<p>Check all relevant documents. They will display as FlipBooks.</p>
[cred_field field='library-books' force_type='field' class='form-check-input' output='bootstrap']
</div>
</div>
<div class="row">
<div class="col-md-12">
[cred_field field='form_submit' output='bootstrap' value='Submit' class='btn btn-primary btn-lg']
</div>
</div>
</div>
[/credform]

#2369193

Thanks for the video,
1) First, as I mentioned above, there isn't such kind of built-in feature to duplicate posts with edit form link

2) In your case, I don't think it needs to duplicate the posts, in my opinion, multiple students can have same lesson, so you can try these:
a) Setup three custom post types:
- Family
- Student
- Lesson
b) Setup two post type relationships:
- One-to-many relationship between "Family" and "Student"
- Many-to-many relationship between "Family" and "Student":
enable intermediate post type, add a custom field "Note" into the intermediate post type
https://toolset.com/course-lesson/many-to-many-post-relationships/

3) In frontend, you can search "Lesson" post by "Family"-> "Student"
And in the single "Student" post, you can display:
- related "Lesson" posts + intermediate posts + custom field "Note"
- A relationship form for user to connect current "Student" post with "Lesson" post, and setup value in custom field "Note"
https://toolset.com/course-lesson/front-end-relationship-forms-for-connecting-posts/

#2369293

My issue is resolved now. Thank you!