Tell us what you are trying to do?
I'm creating a document manager (basically a CRED upload form and a VIEW to list the uploaded documents) to upload files and then list them with a view with different search criteria. I have a Cred form to add a new custom post of type 'document'. I want to assign the current user to a custom field so that I can search with a drop-down select on my view and display all 'document' posts with a given author (since I discovered searching of wordpress fields is not allowed by toolset on drop-down select).
So I created a types field called 'uploaded-by' to hold the current user who creates/authors the post. I thought that would be easiest to allow me to then search for all 'document' posts created/uploaded by a certain user.
Is there any documentation that you are following?
just learning about CRED hooks
Is there a similar example that we can see?
don't think so
What is the link to your site?
local
My action hook so far (not working):
add_action('cred_before_save_data', 'set_default_value_uploaded',10,1);
function set_default_value_uploaded($form_data)
{
// if a specific form
if ($form_data['id']== 18825)
{
$current_user = wp_get_current_user();
$my_display_name = $current_user->display_name ;
// assign current user display name to types custom field 'uploaded-by'
$_POST['wpcf-uploaded-by'] = $my_display_name ;
}
}
I'm assuming that the 'wpcf-uploaded-by' if a single line field.
In this case you will need to update the field like this in the hook.
add_action('cred_save_data', 'set_default_value_uploaded',10,2);
function set_default_value_uploaded($post_id,$form_data)
{
// if a specific form
if ($form_data['id']== 18825)
{
$current_user = wp_get_current_user();
$my_display_name = $current_user->display_name ;
// assign current user display name to types custom field 'uploaded-by'
update_post_meta($post_id,'wpcf-uploaded-by',$my_display_name);
}
}
Please try it like this and let me know if it helps.