Skip Navigation

[Resolved] Incorrect information being populated in Related Ads field

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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 22 replies, has 2 voices.

Last updated by simonM-5 1 year, 11 months ago.

Assisted by: Waqar.

Author
Posts
#2340935

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Simon,

Thank you for waiting.

My proposed setup/changes are working as expected on a clean test website, but I'm having some challenges with making it work on your website's clone.

Either way, I'm confident that I'll be able to get to the bottom of this today and will share the detailed steps and a working duplicator package.

regards,
Waqar

#2344257

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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

#2344259
#2346001
Screenshot 2022-04-21 at 13.42.25.png

Hi Waqar

Thank you for this update. I will have a go at it now.

You are right about the messages not needing to be translated. This simplifies the problem a lot. I had it like that previously but for some reason I changed it. It seems logical though that they don't need translated.

I also like the simplified method of just related ID.

One thing - I'm able to access those files but not able to download them. It is just showing me the error in the screenshot in the corner.

Nevertheless. I will have a go at following your instructions and see how it goes.

Kind regards
Simon

#2346103

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update and glad I could help.

Please take your time to test out the changes and let me know how it goes.

I've shortened the file names in the shared folder, as long file names can cause issues, at times. Try downloading the files now and here are the original file names, so that you can rename them back after downloading:

20220419_nativenannygmbhdev_c5dac6f1d3ee21c76711_20220419015408_archive.daf
20220419_nativenannygmbhdev_c5dac6f1d3ee21c76711_20220419015408_installer.php

#2348519

Hi Waqar

I have made all the changes in the dev environment and we tested it and everything seems to work great! I am now gonna try and replicate the changes in our production site, and once that is done and tested, I think we can close this. I don't wanna close it just yet in case I miss something by accident in production and need your assistance to get it working. I will update you again shortly.

Thanks in the meantime for getting this working for us in dev! Fantastic!

Kind regards
Simon

#2348529

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

I'm very glad that the tests have been successful and I'm confident it will work in the production too.

Let me know if you have any follow-up questions and for a new question or concern, you're welcome to start a new ticket.

#2350493

Hi Waqar

All our tests in the production environment were successful too. THANK YOU so much for this, this has been a big help for us!

As always a pleasure dealing with you!

Kind regards
Simon

#2350499

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.