I have read about a dozen of the other threads concerning auto-generated post titles, but have been unsuccessful in achieving the result.
Here is what we have in functions.php:
/**
* Create custom title from multiple fields
**/
add_action('cred_save_data', 'build_post_title', 10, 2);
function build_post_title($post_id, $form_data)
{
$field1 = get_post_meta($post_id, 'street_address', true);
$field2 = get_post_meta($post_id, 'city_address', true);
$field3 = get_post_meta($post_id, 'state_address', true);
$field4 = get_post_meta($post_id, 'zip_address', true);
In the CRED Form Editor we did the following to hide the Post Title Form Field on the Front End:
<div class="cred-field cred-field-post_title">
<div style="visibility:hidden;">
[cred_field field='post_title' post='vehicle' value='' urlparam='']</div>
</div>
Unfortunately, using the above code results in an error message when submitting the form on the front end and nothing is saved to the database. We also tried using <div style="display:none;"> in the CRED Form Editor and had the same result.
Thank you in advance for helping with this. We are really stumped and can't tell if it's one code snippet or both that has an error.
Thank you Minesh. That snippet is taking care of combining those fields into a working post title. However, I still get an error on the form submission when using the following CSS to hide the title form field in CRED:
"In the CRED Form Editor we did the following to hide the Post Title Form Field on the Front End:
<div class="cred-field cred-field-post_title">
<div style="visibility:hidden;">
[cred_field field='post_title' post='vehicle' value='' urlparam='']</div>
</div>"
Do you know how we can "hide" the form field on the front-end so that users can't see it, while at the same time avoiding the error? Would changing the build_post_title function's action to occur before submission solve this? My thought there is that because WordPress requires a value for the title field before submitting, a pre-submission action would satisfy the requirement.
On top of the continued issue of hiding the Post_Title Form Field, we just noticed that the function for building the title is also applying to the child post which has a separate custom post type and needs to save as a simple text field with no auto-generation of the title. So my question is, can we have the build_post_title function target a single custom post type without affecting the child posts?
Thank you for the help on targeting the cpt. I noticed that when I changed one of my fields to a taxonomy it no longer appears in the post title. I changed state_address to a taxonomy and kept the code in its most recent form but it appears to not recognize the value in the post_title.
Do I need to change this line of code? $field3 = get_post_meta($post_id, 'wpcf-state_address', true);
Specifically do I need to change 'wpcf-state_address'?
I am having trouble understanding the concept in the Codex. Would I use $terms = get_the_terms( $post_id, $taxonomy_slug ); instead of $field3 = get_post_meta($post_id, 'wpcf-state-address', true);
What I mean is would my function look like this to call the term value for the taxonomy:
add_action('cred_save_data', 'build_post_title', 10, 2);
function build_post_title($post_id, $form_data) {