Home › Toolset Professional Support › [Resolved] Displaying related Nanny Ad ID on Messages using Toolset Messaging System
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)
Related documentation:
This topic contains 25 replies, has 2 voices.
Last updated by simonM-5 4 years, 6 months ago.
Assisted by: Minesh.
Tell us what you are trying to do?
We have a Custom Post Type "Nanny Ads". Registered Nanny Users can create multiple Nanny Ads. For potential Family Users viewing the Nanny Ads, we display the New Messsage CRED form, so that these Families can send that Nanny a message using Toolset Messaging system.
When displaying the messages in the user's inboxes (Content Template "Message - single"), we would like to include the Nanny Ad ID (or URL) from which the Message originated, as the family may respond to several different Ads from the same Nanny.
Basically I want to link the two custom post types "Nanny Ad" and "Messages". For example, the Family User viewing the Ad can start multiple Message threads (conversations) regarding the same Ad if they so choose.
Might this be done easily with Relationships or do I have to somehow add the Message ID as a Custom field in the Nanny Ad CPT? If that were the case, how can I handle the fact that
- one Nanny Ad ID could get linked to multiple Message IDs by the same Family User
- multipe Family Users can start a new conversation thread (Message ID) starting from the same Nanny Ad ID
What is the best way to achieve this using Toolset?
Thanks and regards
Simon
Hello. Thank you for contacting the Toolset support.
From the initial information you shared it seems you are aware of the Toolset messaging system.
However - I just would like to know have you checked the following Doc that shared information how you can achieve and implement the messaging system step by step.
=> https://toolset.com/learn/how-to-create-a-messaging-system-with-toolset/
To implement the above messaging system, in your case, I think you just need to replace:
- contractor ID with your nanny Ad's post id [wpv-post-id]
- Message from with current user ID added with [wpv-current-user info=’id’]
- Message to – post author ID of your Nanny ads post (the form is added to the Nanny Ad's page, so when submitted it grabs the data from Nanny ads post [wpv-post-author format=’meta’ meta=’ID’]
Can you please check and give a try, it seems to me it should work.
HI Minesh
Yes, I used the cited documentation and already have Toolset Messaging set up and working.
I'm not sure if you have followed exactly what I am trying to do?
I would like advice on the best way to achieve the following:
-- Linking a Message thread/conversation (Post Type Messages) to a Job Ad (Post Type Job Ads) or a Nanny Ad (Post Type Nanny Ad)
The message in the inbox should be able to display which Ad (Job Ad or Nanny Ad) it was related to.
I have tried adding the Nanny Ad ID and Job Ad ID to the Messages Post Type as Custom Fields following the documentation here:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/using-post-reference-fields-to-display-information-from-a-related-post/
When displaying the message I am then trying to show the Ad Title using the following, however it doesn't seem to work as I imagine it should.
Related Job Ad: [wpv-post-title item="@related-job-ad.parent"]
Related Nanny Ad: [wpv-post-title item="@related-nanny-ad.parent"]
Basically, one can only start a new Message thread whilst viewing either a Job Ad or Nanny Ad. In database terms, this should just be a foreign key to another table, and I should be able to reference any column in that table.
So if I create a new Message thread, one of either the Nanny Ad ID or Job Ad ID will be NULL and the other one will be the ID of the Ad from which the Message started.
If you want some logins to try this out in our site, let me know. I can give you them in a private reply
Kind regards
Simon
Yes - sure. Can you please send e login details as well as tell me on what page you added the following shortcodes?
Related Job Ad: [wpv-post-title item="@related-job-ad.parent"] Related Nanny Ad: [wpv-post-title item="@related-nanny-ad.parent"]
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
When I checked there is no field added to your following form that should store the current job id. So, I've added that required field to the following form:
[cred_field field='related-job-ad' force_type='field' class='form-control' output='bootstrap' select_text='--- not set ---' value='[wpv-post-id]']
=> hidden link
Then, I loggedin as user "nativenanny2 " and go to this post and submit the form with subject and messagge "Minesh – Test1":
=> hidden link
Then, I logged in as user "nativefamily6 " and checked the message listing page:
=> hidden link
- Where with the message listing item Minesh – Test1" - you will see the related "Related Job Ad: Job in Bogenhausen – updated".
HI Minesh
I think you're on the right track now. 🙂 I forgot to add it to the form. I can't view or modify what you have done though, because when I try to open the form "New Message" it tells me that you are editing it and sends me back to All Pages.
Kind regards
Simon
Hi
Is there a special syntax for testing if the field is NULL or not, considering that it is a related field from another post type?
Kind regards
Simon
Hi Minesh
As you have it at the moment, it doesn't make sense, that the user actively has to choose something from a picklist.
Ideally the user shouldn't even see the field on the form and the ID of the Ad would just be stored in the background against the message thread once the user hits the Send Message button.
OR ALTERNATIVELY
If something MUST be shown on the message form, that just the title of the Ad be displayed and it be read-only so the user can't change it. Is this possible?
Thanks and regards
Simon
Is there a special syntax for testing if the field is NULL or not, considering that it is a related field from another post type?
==>
Yes, view's offers [wpv-conditional] shrotcode to display conditional output. However, what field you would like to display conditionally?
More info:
=> https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/
As you have it at the moment, it doesn't make sense, that the user actively has to choose something from a picklist.
Ideally the user shouldn't even see the field on the form and the ID of the Ad would just be stored in the background against the message thread once the user hits the Send Message button.
==>
Ok. Is everything else is sorted out, If yes, then let me know I will hide that field from the form.
HI Minesh
Our endgoal is the following:
A user clicks on Messages and in his inbox sees:
THOMAS MÜLLER (this is the message sender)
Subject: asdfadsfa (title of the message post)
Related Ad: asdfasdfasd (title or URL of the related Ad)
However,
- families who view their inbox should only see Messages related to Nanny Ads.
- nannies who view their inbox should only see Messages related to Job Ads.
So either I would need to duplicate the New Message Form to have one for Job Ads and one for Nanny Ads, eg New Message from Job Ad Form and New Message from Nanny Ad Form.
But I was trying to think of a way to do this all elegantly in one form.
Alternatively, when displaying the Messages in the users' inboxes via Received Messages View, one could think about suppressing one of the Ad IDs. That could also be a solution.
FYI:
1) I changed select_text='--- not set ---' to select_text='[wpv-post-title]' so the correct title was picked immediately as the default value, this worked fine.
I also experimented with the following, but neither gave me a satisfactory solution:
2) I tried setting readonly='true', which worked as readonly, but then it didn't store the ID of the Ad, so it doesn't show when viewing Messages.
3) I tried using cred_generic_field (instead of cred_field) analogous to the other fields created by Toolset, setting hidden='true' but that didn't work either. The Related Ad was not shown when viewing the Message.
Also I would prefer that the Title or URL doesn't appear as a select dropdown, rather simply as a text within the form, if that is possible with Post Reference fields, as I imagine it is. I looked for documentation on correct syntax for displaying the field but couldn't find anything.
Thanks and regards
Simon
However,
- families who view their inbox should only see Messages related to Nanny Ads.
- nannies who view their inbox should only see Messages related to Job Ads.
So either I would need to duplicate the New Message Form to have one for Job Ads and one for Nanny Ads, eg New Message from Job Ad Form and New Message from Nanny Ad Form.
==>
How would you like to go with as both ways are possible.
Alternatively, when displaying the Messages in the users' inboxes via Received Messages View, one could think about suppressing one of the Ad IDs. That could also be a solution.
==>
Yes, that is also correct. that is also possible.
FYI:
1) I changed select_text='--- not set ---' to select_text='[wpv-post-title]' so the correct title was picked immediately as the default value, this worked fine.
I also experimented with the following, but neither gave me a satisfactory solution:
2) I tried setting readonly='true', which worked as readonly, but then it didn't store the ID of the Ad, so it doesn't show when viewing Messages.
3) I tried using cred_generic_field (instead of cred_field) analogous to the other fields created by Toolset, setting hidden='true' but that didn't work either. The Related Ad was not shown when viewing the Message.
===>
Can you confirm all above three steps you done to hide the field, if this is correct, You should rollback to original state where it displays the field and I will add the code to hide the field - does that makes sense for you?
Also I would prefer that the Title or URL doesn't appear as a select dropdown, rather simply as a text within the form, if that is possible with Post Reference fields,
==>
Again which field you are talking about. Can you perform and take things step by step rather talking about many things. One issue one ticket.
HI Minesh
One issue one ticket. So far I only have one issue: I want to store a related Ad ID in the database so I can display the URL or title of the Ad against a Message. That's it.
As the solution you provided was not 100% satisfactory, I tried a few other things. That's all.
Our requirements are quite simple:
1) Store the Related Job Ad ID or Nanny Ad ID against the Message when it is submitted in the Post Form "New Message" using cred_field, hidden cred_generic_field or some other method
2) If possible, not have to show any attributes from the Ad on the Message Form when viewing it on the front end (ie so that the only two fields the user sees are Message Subject and Message Text and the linking of Message and Job Ads (or Messages and Nanny Ads) becomes invisible to user)
3) Display either the Ad URL either as a link to the Ad or simply the Title as information to user when viewing the message using View "Messages received"
Whether that is achieved with hidden cred_field, hidden cred_generic_field or some other method is unimportant. Important is the result and the user experience.
Again, our end goal is the following when viewing View "Messages received":
THOMAS MÜLLER (this is the first and last name of the message sender)
Subject: asdfadsfa (URL of the Message post)
Related Ad: asdfasdfasd (URL or title of the related Ad)
Can you please let me know right away if you have understood our requirements clearly, before asking me to open more tickets for the same issue.
Thanks and best regards
Simon
Our requirements are quite simple:
1) Store the Related Job Ad ID or Nanny Ad ID against the Message when it is submitted in the Post Form "New Message" using cred_field, hidden cred_generic_field or some other method
==>
Ok. Done.
2) If possible, not have to show any attributes from the Ad on the Message Form when viewing it on the front end (ie so that the only two fields the user sees are Message Subject and Message Text and the linking of Message and Job Ads (or Messages and Nanny Ads) becomes invisible to user)
==>
Ok. Done.
3) Display either the Ad URL either as a link to the Ad or simply the Title as information to user when viewing the message using View "Messages received"
==>
Ok
As you wanted to hide the "related-job-ad' or "related-nanny-ad" field on the message form, both field are added using the hidden generic fields as you can see with the following form:
=> hidden link
- In addition to that I've added another hidden generic field to the above form that will be used to identify the form is submitted from which post type so that we can know that the message form is submitted from job-ad or nannay ad.
[cred_generic_field type='hidden' field='current-posttype'] { "default":"[wpv-post-type]" } [/cred_generic_field]
Now, to connect the message post with related job-ad or nannay ad I've added the following code to "toolset-custom-code" snippet under the "Custom Code" section of Toolset:
=> hidden link
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){ 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 ); } } }
Now, when I submit a message loggedin as: nativenanny2 user from the following link:
=> hidden link
- I can see the message is associated with correct job-ad
and when I submit a message form loggedin as: nativefamily6 user from the following link;
=> hidden link
- I can see the message is associated with correct nanny-ad.
Can you please confirm this much flow works now.
And let me know if you want to do any further corrections and where exactly.
HI Minesh
Thanks.. On the first glance it appears to work. I will test it more intensively tonight or latest tomorrow and give you more qualified feedback.
Kind regards
Simon
Ok great. Please let me know once you test it.