This support ticket is created vor 6 Jahren, 8 Monaten. 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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
Tell us what you are trying to do? I built a front-end CRED form for submitting new custom post listing - camps - and would like to automatically assign the new listing/post to an existing user account - a house account.
Is there any documentation that you are following?
I've looked at the CRED documentation for front-end forms, and have done Google and forum searches, but haven't found what I've looking for.
Is there a similar example that we can see?
Not that I know of.
What is the link to your site? Here's a link to the form on the site: versteckter Link
Hello. Thank you for contacting the Toolset support.
You can use CRED hook cred_save_data hook to set the post author.
For example:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data){
// if a specific form
if ($form_data['id']==999) {
$my_post = array(
'ID' => $post_id,
'post_author' => 7777
);
// Update the post into the database
wp_update_post( $my_post );
}
}
Where:
- Replace 999 with your original CRED form Id
- Replace 777 with your desired post author ID
Minesh - this sounds perfect. But I've never worked with Hooks. Where do I place the code? I've read all your documentation and examples on using hooks and CRED hooks, but nowhere does it actually tell you where and how you place the code?
I tried using
...
placed right before [cred_field field='form_submit' tag but it just displayed the code on the frontend.
Sorry - my last message didn't display correctly. I meant to indicate that I used the code tags as a container for the hook code you provided, but that didn't work.
For multiple IDs you should use the following code:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data){
// if a specific form
if ($form_data['id']==999 OR $form_data['id']==888 ) {
$my_post = array(
'ID' => $post_id,
'post_author' => 7777
);
// Update the post into the database
wp_update_post( $my_post );
}
}
Where:
- Replace 999 and 888 with your original form IDs