Hi Simon,
I apologize for the delay in getting back on this, as I wasn't feeling well over the weekend.
The default behavior of the generic fields in forms is that their values are not saved in the database, like other custom fields. However, if "persist":1, is set then that generic field's value is saved in the databases. This is why the fields for the related nanny ad and the related job ad both were populating in your tests.
Now that you're not using the post relationships for connecting messages with the nanny or job ads, I would recommend removing the two separate related ad fields and including a single common "Related Ad" field.
( screenshot: hidden link )
In my tests, this worked reliably in the context of WPML and where users used the messaging system in different languages.
( I'll share the duplicator package in a separate private reply )
Note: Strictly technically speaking, I don't see why the "Messages" post type needs to be translatable. The only item of interest in that post type, other than custom fields is the post content/body that holds the actual message text. I don't think you plan on translating the text in those messages, either manually or automatically. If you agree, you can set the "Messages" post type to be "not translatable" in the WPML settings and remove form IDs "1250" and "1251" from the custom code snippet "sync_language_duplicates_on_submission", so that language duplicates are not created for this post type.
Here are the details of the changes:
1. The code snippet "func_connect_hidden_ids_messages" is no longer needed and you can remove that.
2. Form "Post Form - New Message".
As we'll be using a single common field for the related ad, you can remove the generic fields for the "current-posttype", "wpcf-related-nanny-ad", and "wpcf-related-job-ad":
[cred_generic_field type='hidden' field='current-posttype']
{
"default":"[wpv-post-type]"
}
[/cred_generic_field]
[cred_generic_field type='hidden' field='wpcf-related-job-ad' class='']
{
"required":1,
"validate_format":0,
"persist":1,
"default":"[wpv-post-id]"
}
[/cred_generic_field]
[cred_generic_field type='hidden' field='wpcf-related-nanny-ad' class='']
{
"required":1,
"validate_format":0,
"persist":1,
"default":"[wpv-post-id]"
}
[/cred_generic_field]
Instead, you can include the generic field for the common field "related-ad":
[cred_generic_field type='hidden' field='wpcf-related-ad' class='']
{
"required":1,
"validate_format":0,
"persist":1,
"default":"[wpv-post-id]"
}
[/cred_generic_field]
3. Form "Post Form - Reply Message".
In this form too, you'll remove the conditional display code to include the two separate related ad fields:
<!-- adding related nanny ad field and post type -->
[wpv-conditional if="( '[wpv-post-id item='@related-nanny-ad.parent']' ne '' )"]
[cred_generic_field type='hidden' field='current-posttype']
{
"default":"nanny-ad"
}
[/cred_generic_field]
[cred_generic_field type='hidden' field='wpcf-related-nanny-ad' class='button']
{
"required":1,
"validate_format":0,
"persist":1,
"default":"[wpv-post-id item="@related-nanny-ad.parent"]"
}
[/cred_generic_field]
[/wpv-conditional]
<!-- adding related job ad field and post type -->
[wpv-conditional if="( '[wpv-post-id item='@related-job-ad.parent']' ne '' )"]
[cred_generic_field type='hidden' field='current-posttype']
{
"default":"job-ad"
}
[/cred_generic_field]
[cred_generic_field type='hidden' field='wpcf-related-job-ad' class='']
{
"required":1,
"validate_format":0,
"persist":1,
"default":"[wpv-post-id item="@related-job-ad.parent"]"
}
[/cred_generic_field]
[/wpv-conditional]
Instead, you can include the generic field for the common field "related-ad":
[cred_generic_field type='hidden' field='wpcf-related-ad' class='']
{
"required":1,
"validate_format":0,
"persist":1,
"default":"[types field='related-ad' output='raw'][/types]"
}
[/cred_generic_field]
4. Views "Messages - Outbox" and "Messages - Inbox".
In both these views, you'll replace:
<td>[wpv-post-link item="@related-nanny-ad.parent"][wpv-post-link item="@related-job-ad.parent"]</td>
With:
<td>[wpv-post-link item="[types field='related-ad'][/types]"]</td>
5. Content template "Message - single".
In this template, you'll replace:
[wpv-post-link item="@related-nanny-ad.parent"][wpv-post-link item="@related-job-ad.parent"]
With:
[wpv-post-link item="[types field='related-ad'][/types]"]
These are all the changes that you'll need and I'm going to share a private reply with you for the duplicator package and the test user access details.
regards,
Waqar