Skip Navigation

[Resolved] Add video uploaded via CRED to post

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

Problem:

I want to do is use one of the CRED API hooks after the form is submitted to add a meta value to the corresponding post.

Solution:

Yes, you are right, you can use CRED action hook "cred_save_data" to update/add custom field to the post, see the document you mentioned above:

https://toolset.com/documentation/programmer-reference/cred-api/#csd

But, it needs custom codes, for example, when user submit the CRED form, the post is saved into database, you can use hook "cred_save_data" to trigger a custom PHP function, in this function, you need to:

1) get the value of "URL of the video uploaded", if it is a custom field created with Types plugin, you can use Types function types_render_field() to get the field value:

https://toolset.com/documentation/customizing-sites-using-php/functions/

Or you can use WordPress function get_post_meta() to get the value:
https://codex.wordpress.org/Function_Reference/get_post_meta

2) use above value to update/add it to the "meta value", for example
https://developer.wordpress.org/reference/functions/update_post_meta/

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-api/#csd

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

Last updated by TomT2847 6 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#632096

Hi there,

On my site, there's an option for users to submit posts (via a CRED form) to the site and upload videos related to their post that will be published with it. I want to attach these videos to the corresponding post in some way. I'm thinking the best way of doing that would be to attach it as post meta data. What is the best way to do this? I looked at the hooks (https://toolset.com/documentation/programmer-reference/cred-api/#csd) and thought cred_save_data would be the most suitable, but I'm not sure.

Thanks for any help!

#632228

Hello,

I suggest you create a custom video field with Types plugin, then put the video field into CRED form for user upload the video files, and display the video field value using Types shortocde:
https://toolset.com/documentation/customizing-sites-using-php/functions/#video

#635849

I don't think that would work with the way the site is set up. I think I just want to add a meta value attached to the post that contains a url to the video that's uploaded via the form. How would I do that?

#637843

That depends on your self, if you only need to store the Video's URL, you can setup a custom URL field, same as above:
1) create a custom URL field with Types plugin
2) put the URL field into CRED form for user fill the Video's URLs
3) display the URL field value using Types shortocde:
https://toolset.com/documentation/customizing-sites-using-php/functions/#url

#651176

Hi Luo. Thanks for the response. Unfortunately, that's not what I'm looking to do. Here's what I want to happen:

1) User submits post title, post content, and then uploads a video using a post submission form.
2) I want to then save a meta value to the post containing the url of the video uploaded.
3) The admin goes to the draft post submitted by the user, sees the meta field with the URL of the video uploaded, and then manually displays the video.

So what I want to do is use one of the CRED API hooks after the form is submitted to add a meta value to the corresponding post. I don't know what hook to use though. Would it be cred_save_data?

#651813

For your question:
So what I want to do is use one of the CRED API hooks after the form is submitted to add a meta value to the corresponding post.

Yes, you are right, you can use CRED action hook "cred_save_data" to update/add custom field to the post, see the document you mentioned above:
https://toolset.com/documentation/programmer-reference/cred-api/#csd

But, it needs custom codes, for example, when user submit the CRED form, the post is saved into database, you can use hook "cred_save_data" to trigger a custom PHP function, in this function, you need to:
1) get the value of "URL of the video uploaded", if it is a custom field created with Types plugin, you can use Types function types_render_field() to get the field value:
https://toolset.com/documentation/customizing-sites-using-php/functions/
Or you can use WordPress function get_post_meta() to get the value:
https://codex.wordpress.org/Function_Reference/get_post_meta

2) use above value to update/add it to the "meta value", for example
https://developer.wordpress.org/reference/functions/update_post_meta/

#675572

Thanks, figured it out. For those who want to do something similar, here's the code:


// Specifically only adds action to form with an ID of 12
add_action('cred_save_data_12', 'save_data_for_form_with_id_12',10,2);

function save_data_for_form_with_id_12($post_id, $form_data)
{
    if (isset($_POST['Video']))
    {
        add_post_meta($post_id, 'Video URL', $_POST['Video'], true);
    }
}