Skip Navigation

[Resolved] Displaying related Nanny Ad ID on Messages using Toolset Messaging System

This support ticket is created 4 years, 6 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 25 replies, has 2 voices.

Last updated by simonM-5 4 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#1653423

Hi Minesh

We're almost there! The output works fine when viewing the messages.... until I put it inside conditional statements.

I need to test for the role of the current user so I can only show the following to Nannies ...
REGARDING JOB AD: [wpv-post-link item="@related-job-ad.parent"]

... and the following to Families:
REGARDING NANNY AD: [wpv-post-link item="@related-nanny-ad.parent"]

So the following statements work fine on their own, until I put it inside conditional statements :
[wpml-string context='wpv-views-messages-inbox' name='REGARDING JOB AD']REGARDING JOB AD[/wpml-string]: [wpv-post-link item="@related-job-ad.parent"]

[wpml-string context='wpv-views-messages-inbox' name='REGARDING NANNY AD']REGARDING NANNY AD[/wpml-string]: [wpv-post-link item="@related-nanny-ad.parent"]

I found 3 different methods for conditional statements, depending on which documentation you land on, but I tried all 3 and when I enclose the working statements above in conditional brackets, they stop showing the related Ads:

METHOD 1 (using the conditional output button in the Loop Editor), for example:
Checking if user is role 'native_nanny':
[wpv-conditional if="( '[wpv-post-get-wp-user-role]' eq 'native_nanny' )"]
[wpml-string context='wpv-views-messages-inbox' name='REGARDING JOB AD']REGARDING JOB AD[/wpml-string]: [wpv-post-link item="@related-job-ad.parent"]
[/wpv-conditional]

Checking if user is role 'family' or 'subscribed_family':
[wpv-conditional if="( '[wpv-post-get-wp-user-role]' eq 'family' ) OR ( '[wpv-post-get-wp-user-role]' eq 'subscribed_family' )"]
[wpml-string context='wpv-views-messages-inbox' name='REGARDING NANNY AD']REGARDING NANNY AD[/wpml-string]: [wpv-post-link item="@related-nanny-ad.parent"]
[/wpv-conditional]

METHOD 2: Legacy [wpv-if][/wpv-if] notation, for example:
[wpv-if evaluate=" '[wpv-post-get-wp-user-role]' = 'native_nanny' "]
[wpml-string context='wpv-views-messages-inbox' name='REGARDING JOB AD']REGARDING JOB AD[/wpml-string]: [wpv-post-link item="@related-job-ad.parent"]
[/wpv-if]

METHOD 3: Using notation documented in https://toolset.com/forums/topic/testing-user-role-to-conditionally-display-content/:
[wpv-conditional if="( '[wpv-current-user info='role']' eq 'native_nanny' )"]
[wpml-string context='wpv-views-messages-inbox' name='REGARDING JOB AD']REGARDING JOB AD[/wpml-string]: [wpv-post-link item="@related-job-ad.parent"]
[/wpv-conditional]

None of the 3 conditional notations is working. Any ideas?

Thanks and regards
Simon

#1654061

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

The method 2 is outdated one, you should not use that.

You should go with method 3 as with that method you are using the correct shortcode to get the current user role.

Can you please share on what page/link you have try to add the above conditional code and I will correct it.

#1654073

Hi Minesh

I tried on the View "Messages - Inbox".

Thanks and regards
Simon

#1654099

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It seems you have added wrong things to display with your conditional statements.

You have added the following conditional statements:

[wpv-conditional if="( '[wpv-current-user info='role']' eq 'native_nanny' )"]
      <h3>[wpml-string context='wpv-views-messages-inbox' name='REGARDING JOB AD']REGARDING JOB AD[/wpml-string]: [wpv-post-link item="@related-job-ad.parent"]</h3>
    [/wpv-conditional]
    [wpv-conditional if="( '[wpv-current-user info='role']' eq 'family' ) OR ( '[wpv-current-user info='role']' eq 'subscribed_family' )"]
		<h3>[wpml-string context='wpv-views-messages-inbox' name='REGARDING NANNY AD']REGARDING NANNY AD[/wpml-string]: [wpv-post-link item="@related-nanny-ad.parent"]</h3>
	[/wpv-conditional]

Where you added native_nanny role to display the Job Ads but its creating the nanny ads - corrct?
so, it should display nanny ad

The same way you added family role to display the NANNY Ad but the family role creates the job ad - correct?
so, it should display job ad

#1654183

Hi Minesh

Yes, you are right, when a Nanny goes into her message inbox, she should see responses to her Nanny Ads and Families should see responses to their Job Ads... I have changed this.

Now the only remaining problem is that the Replies to the messages don't have the same linkage to the Ads, because they are generated from the "Post Form - Reply Message" (1251).

The custom code you wrote ("toolset-custom-code") applies only to form "Post Form - New Message" (1250). I'm not a PHP developer and want to avoid Custom Code wherever possible. Looking at your code it seems to do the following: "When form 1250 is submitted, if the current post type is a Job Ad, then store the related Job Ad ID, otherwise if current post type is a Nanny Ad then store the related Nanny ID."

Question: Surely, it is possible to achieve our goal without any Custom Code, eg by using Relationship Forms or some other mechanism? While I understand that Custom Code is useful and sometimes necessary, it should only be used as a last resort when it is not possible to achieve the desired result via the user interface.

From a database perspective the Related Job Ad ID or Related Nanny Ad ID should be stored on the Message record (or in the intermediary table between Job Ads and Messages or Nanny Ads and Messages) and must therefore somehow be retrievable from the database to display on the replies as well.

1) Can you please confirm that all of this is NOT possible using the standard user interface?
2) How can we get the associated Ad to display on the replies as well?

Thanks and best regards
Simon

#1654193

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Question: Surely, it is possible to achieve our goal without any Custom Code, eg by using Relationship Forms or some other mechanism? While I understand that Custom Code is useful and sometimes necessary, it should only be used as a last resort when it is not possible to achieve the desired result via the user interface.
==>
Relationship forms are different thing that are only used to connect the posts of different post types.

1) Can you please confirm that all of this is NOT possible using the standard user interface?
-- Yes, the code I've shared is required as we added the related post ids as hidden fields.

2) How can we get the associated Ad to display on the replies as well?
- Do you mean that on the following page when I loggedin as user: nativenanny2
=> hidden link
- When I click on the subject line on 2nd record "New message from Thomas to Siobhan" - its displaying the following reply form:
=> hidden link
-With the above reply form, you want to display the related nanny ad " Test Map in German Nanny Ad – Single" - correct?

#1654221
Screenshot 2020-06-08 at 14.56.34.png

Hi Minesh

1) Ok, that's a shame, but thanks for confirming.

2)
a) I logged in as nativefamily6, went to Find a Native Nanny, clicked View Ad and sent a message. A new thread is started "NEW THREAD – 1st message from nativefamily6 to nativenanny2"
b) I logged in as nativenanny2, see the message entitled "NEW THREAD – 1st message from nativefamily6 to nativenanny2" AND the related Nanny Ad "Test Map in German Nanny Ad – Single".
c) I send a reply to this message as nativenanny2 by clicking the Subject line.
d) I refresh my messages logged in as nativefamily6. I can see the reply sent by nativenanny2 and reply back to her.
3) Now, as nativenanny2 when I refresh my inbox, the Related Nanny Ad information is missing, presumably because the URL of the Subject Line is changing and therefore is a different message post_id.

The goal is to maintain the "Related Nanny Ad" or "Related Job Ad" information throughout the entire conversation thread, so that each message created is always linked with the Nanny Ad ID or Job Ad ID from the initial message in the conversation thread.

Kindly let me know if there is any uncertainty.

Thanks and regards
Simon

#1655313

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

2)
a) I logged in as nativefamily6, went to Find a Native Nanny, clicked View Ad and sent a message. A new thread is started "NEW THREAD – 1st message from nativefamily6 to nativenanny2"
==>
OK

b) I logged in as nativenanny2, see the message entitled "NEW THREAD – 1st message from nativefamily6 to nativenanny2" AND the related Nanny Ad "Test Map in German Nanny Ad – Single".
==>
Ok

c) I send a reply to this message as nativenanny2 by clicking the Subject line.
==>
OK

d) I refresh my messages logged in as nativefamily6. I can see the reply sent by nativenanny2 and reply back to her.
==>
Ok.

3) Now, as nativenanny2 when I refresh my inbox, the Related Nanny Ad information is missing, presumably because the URL of the Subject Line is changing and therefore is a different message post_id.

The goal is to maintain the "Related Nanny Ad" or "Related Job Ad" information throughout the entire conversation thread, so that each message created is always linked with the Nanny Ad ID or Job Ad ID from the initial message in the conversation thread.
==>
Ok

I've adjusted the fields for "Reply Message" form as you can see with your form:
=> hidden link

I suggest, you should remove all other dummy messages so we can test with fresh messages.

Please make sure that you create nanny-ad when you login as nativenanny2 and job-ad when you login as nativefamily6.

I've also adjusted the custom code section code that should be triggered now when you submit New Message form as well as Reply message form:


add_action('cred_submit_complete', 'func_connect_hidden_ids_messages',10,2);
function func_connect_hidden_ids_messages($post_id, $form_data){
    // if a specific form
    if ($form_data['id']==1250 or $form_data['id']==1251){
      
      if(isset($_POST['current-posttype']) and $_POST['current-posttype']=='job-ad'){
        		  toolset_connect_posts( 'related-job-ad',$_POST['wpcf-related-job-ad'], $post_id);
      }else if(isset($_POST['current-posttype']) and $_POST['current-posttype']=='nanny-ad'){
        		 toolset_connect_posts( 'related-nanny-ad',$_POST['wpcf-related-nanny-ad'], $post_id );
      }
        
    }
  
   
}

Can you please remove all dummy messages and start with fresh message and check if that works and let me know if you require further help.

#1662881

HI Minesh

We are testing this further today and will give you feedback by the end of the day, but it looks good so far! 🙂

Thanks and regards
Simon

#1662937

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok great 🙂

#1663679

Hi Minesh

We are now able to display the related IDs successfully. The rest is just a formatting issue, which I can handle myself.

My issue is resolved now. Thank you!