Skip Navigation

[Resolved] Single messages template

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 11 replies, has 2 voices.

Last updated by Waqar 1 year, 7 months ago.

Assisted by: Waqar.

Author
Posts
#2602495
Untitled-mail1.jpg

I have a minor problem that when looking at single messages, not only the single message (or other treat messages) will be shown also a lot of other messages or content (which nothing has to do with the email-treat) are displayed. A more detailed explanation is attached.

#2602743

Hi,

I tried to log in to the website's admin area, but the previously shared access details no longer work.

Can you please share temporary admin login details, again so I can see how this template is set up?

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

regards,
Waqar

#2602817

Thank you for sharing the access details.

The messaging system needs to store the ID of the first message of the thread, in the custom field 'First Message ID' ( slug: 'first-message-id' ).

But currently, the new message form ( 'New message' ), is not saving that value.

To achieve this, you can use a custom function attached to the 'cred_save_data' hook, that updates this field's value when the form is submitted.
( ref: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data )

For example:


add_action('cred_save_data', 'custom_new_message_form_action',10,2);
function custom_new_message_form_action($post_id, $form_data)
{
	// if a specific form
	if ($form_data['id']==562)
	{
		$key = 'wpcf-first-message-id';
		update_post_meta( $post_id, $key, $post_id );
	}
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

After this, any new messages that you'll create through this form will have the correct custom field value and will show only the related messages, on the single message post page.

#2603701
message-content.png

I followed your instructions and now it works! Thank you! The only problem is that the message content is not displayed. I have drawn it for you in the attachment. There seems to be a detail missing in the code. Template hidden link

#2604351

Glad that it is working now.

The message's content is saved in the custom field 'Nachricht'.

In the view named 'Related messages', you can replace the shortcode that shows the post content:


[wpv-post-body view_template="None"]

With the shortcode that shows the content from the 'Nachricht' field:


[types field='nachricht'][/types]

#2604531
Untitled-6.png

Thank you Waqar! But unfortunately, there are still 2 things to be worked on (I can't say that the toolset is easy to use without programming knowledge). See attached.

Thanks.

#2605527

Hi Waqar,

have you had a chance to look at it?

#2605687

Thank you for waiting, as I looked into the new questions.

> I can't say that the toolset is easy to use without programming knowledge

- The messaging system that you're building is not something that is available out of the box. For this reason, a number of extra steps and some code customization is needed to make different components work together.

Now, that the first form 'New message' is working correctly, the next step is to adjust the second form 'Reply message'. It is the same form that is showing in your screenshot, from the single message post page.

I'll recommend opening both these forms in two different browser tabs side by side and removing all the fields from the 'Reply message' form.

Next, you can add the fields in this form the same as in the 'New message' form. One additional hidden field that you'll need to include would have slug 'wpcf-first-message-id' and in the default value the shortcode [types field='first-message-id' output='raw'][/types].

This way the 'first-message-id' custom field's value will be carried over to the reply message too.

#2606093
message2.png

Hi Waqar,

>The messaging system that you're building is not something that is available out of the box. For this reason, a number of extra steps and some code customization is needed to make different components work together.

Oh, I thought the toolset messaging system worked like that by default.
Then I thank you again for your help and maybe this thread will help others who want to do something similar.

I have followed your instructions and we are getting closer and closer to the goal! There are still 3 things that don't quite work after sending the reply message. I have attached a drawing of it for you.>

Thank you!

#2607559

Thanks for writing back.

1. To stop the 'Reply message' form to redirect to the newly created message post, the 'After visitors submit this form' option in the form to 'Keep displaying this form'.
( it was previously set to 'display the post' )
screenshot: hidden link

2. This same form was also missing the 'Message Title' field. I've added it so that the user can set the title of the reply message and it doesn't use the automatically generated title.

#2607673

Hi Waqar,

Thank you again for your help.
I have tested it, it works!

But is it really necessary to always include another "reply title" when replying to messages?
Can this field also be specified as "hidden" (if it is really necessary) and the replies always use the title of the entire message conversation? Or even better, the message creator is always named as the title;
"Hans wrote:"
"Michael wrote:"

Thank you!

#2608771

Including the 'Message Title' field in the reply form is unnecessary. However, without the title field, the form will create a new message post with the automatically generated title ( for example: 'CRED Auto Draft .......' ).

If you don't want users to fill in the title of each reply post, you can hide this field with some CSS code, and in that field's default value, use something like:


[wpv-current-user info='name'] wrote

This will set the message post title in the format: '{current user's name} wrote'

Or you can add:


Reply message to: [wpv-post-title item='{{wpv-post-field name='wpcf-first-message-id'}}']

This will set the message post title in the format: Reply message to: {title of the first message in the thread}

The advantage of this format is that when you see the list of message posts in the admin area, you'll have an idea from the title about which conversation this particular message belongs to.

And if you don't want to show each message post's titles in the list of messages on the front end, you can replace [wpv-post-title] in the loop editor of the view 'Related messages' with:


[wpv-user field='user_firstname' id="[types field='nachricht-von'][/types]"] wrote:

This will show the first name of the user who wrote each message.