Skip Navigation

[Resolved] CREATE a playlist/collection and ADD post with ONE click?

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

Problem: I would like to create a playlist feature so Users can add a video to an existing playlist or create a new playlist and automatically add the video to that playlist.

Solution:
There's no JavaScript API for Forms, so the best approach in this case is to use one Form and some custom code with the cred_save_data API. In the cred_save_data callback function, create a new playlist post programmatically using the wp_insert_post function. Then use the post relationships API toolset_connect_posts to connect the new playlist and new post.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://developer.wordpress.org/reference/functions/wp_insert_post/
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

This support ticket is created 5 years, 11 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
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)

This topic contains 2 replies, has 2 voices.

Last updated by a.R 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1193670

a.R

Hi,
we would like to create a playlist-/collection-function similar to the one in youtube.

User should be able to
- add a post to an existing playlist OR
- create a new playlist and automatically add the post to this one.

For each task there is a CRED form shown besides each other, which should both be submitted with one same click (jquery).
The problem is, until actually CREATING the playlist, it doesn´t have an ID, which I could pass to the other form to tell, that the post is to be inserted in this playlist.

Maybe one could use the playlist-created-message to hide the second form there and actually by clicking OK create the playlist entry?
If yes: where do I find the ID of the newly created playlist in that moment?

Or do you see a better chance to do that?

THANK YOU, regards, Achim

#1193878

Hi, there's no JavaScript API for Forms, so the best approach in this case is to use one Form and some custom code with the cred_save_data API. In the cred_save_data callback function, create a new playlist post programmatically using the wp_insert_post function. Then use the post relationships API toolset_connect_posts to connect the new playlist and new post.

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://developer.wordpress.org/reference/functions/wp_insert_post/
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

Let me know if you have questions about this approach.

#1197103

a.R

Oooh, this sounds quite complicated to me, as I am no real coder...
Maybe I will try that one time. This is a big wish, clear.

My issue is resolved for now. Thank you!