I'd like to change the generic name of a form started by _CRED...
In my form I have related post values:
[cred_field field='@company-order.parent' class='form-control' output='bootstrap' select_text='--- not set ---' required='true']
[cred_field field='@film-order.parent' class='form-control' output='bootstrap' select_text='--- not set ---']
I want the name of my post created by the form to be
Company- Film - Date
To retrieve the data of the parent fields @film-order.parent and @company-order.parent in your WordPress script, you can use the $_POST superglobal array. Here's how you can modify your script to retrieve those values:
add_action('cred_save_data', 'func_custom_post_title', 10, 2);
function func_custom_post_title($post_id, $form_data)
{
if ($form_data['id'] == 222) {
$posting_date = date('d m Y');
// Retrieving values from $_POST
$film_parent = isset($_POST['wpcf-@film-order.parent']) ? $_POST['wpcf-@film-order.parent'] : '';
$company_parent = isset($_POST['wpcf-@company-order.parent']) ? $_POST['wpcf-@company-order.parent'] : '';
// Assuming $film_parent and $company_parent are IDs, you can get their titles
$film = get_the_title($film_parent);
$company = get_the_title($company_parent);
$date = $posting_date;
$title = $film . '-' . $company . '-' . $date;
$args = array('ID' => $post_id, 'post_title' => $title);
wp_update_post($args);
}
}
PS : This script is only an example that will retrieve the parent IDs from the $_POST superglobal array, then get their titles using get_the_title() function. Ensure that the values are properly sanitized and validated before using them in your code. Also, make sure that the field names (wpcf-@film-order.parent and wpcf-@company-order.parent) are correct. If they are different, adjust the script accordingly.
Unfortunately, the form to create a new post is in a page called "New Order" and sot the title that the script gives me is "New Order - New Order - Date.
It takes twice the title of the page instead the values of the related posts.
Knowing that in my form I have this:
[cred_field field='@company-order.parent' class='form-control' output='bootstrap' select_text='--- not set ---' required='true']
[cred_field field='@film-order.parent' class='form-control' output='bootstrap' select_text='--- not set ---']
Are "wpcf-@film-order.parent" and "wpcf-@company-order.parent" the right syntax ?
I'm sorry for the delay in response as I had to double check with our team before suggesting a solution,
So the form fields such as field='@company-order.parent' is a field to select a parent post that the child post (which the form will publish) should belong to.
The relationship is a relationship between company (parent) and order (child) post types, and the .parent indicates the field refers to the parent.
So field='@company-order.parent' will have the post ID of the parent company post.
You can get that value from the $_POST object, but your example you shared with the client (that you got from the client) uses the wrong properties. Here's an example of the $_POST object from a test site that has a project < task relationship: