Skip Navigation

[Resolved] Send email to post author if relationship is made

This thread is resolved. Here is a description of the problem and solution.

Problem:

Send email notification when submit the relationship form.

Solution:

You will need to consider custom codes, for example, after user submit the relationship form, use action hook "toolset_association_created" to trigger a PHP function, for example:

https://toolset.com/forums/topic/send-email-to-post-author-if-relationship-is-made/#post-1883283

Relevant Documentation:

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_association_created

This support ticket is created 4 years 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
- 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/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by bramV-4 3 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1881961

Hi
I've got 2 types of Custom Posts. 1 Search, 2 horse

There is a many to many. relationship. Using a front end relationship form a user can connect his horse to another user's Search.
2 questions

1. How can I - frontend - show the horses connected to a Search in the Search, but only visible to the author of the Search
2. How can I notify the author of the search whenever a horse is added to his/her Search post through the form.

Thx

#1882431

Hello,

Q1) Please elaborate the question with more detail:

show the horses connected to a Search in the Search

Where are we talking about? single "Search" post or search result post of "Search" list?
If it is search result post of "Search" list?
You can try the author filter, see our document:
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-author/
Post author is the same as the logged in user

Q2) There isn't such a built-in feature within Toolset Forms plugin, the relationship form does not support Email notification setting, you can add a feature request for it, our developers will evaluate it:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#1882477

Hi, Luo

Thank you
1. Search = a single post.
2. IS there a work away around? I saw this feature is already talked about since 2018. Would really help if there a possible work around

#1883283

Q1) You can setup a post view to show related horse posts:
https://toolset.com/course-lesson/displaying-related-posts/#displaying-many-related-items

You can check current logged-in user is current "Search" post's author with wpv-conditional shortcode, for example:

[wpv-conditional if="( '[wpv-current-user info='user_login']' ne '[wpv-post-author format='meta' meta='user_login']' )"]
Here display post view's shortcode
[/wpv-conditional] 

Q2) You will need to consider custom codes, for example, after user submit the relationship form, use action hook "toolset_association_created" to trigger a PHP function:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_association_created

In this PHP function, get the related "Search" post author email:
https://developer.wordpress.org/reference/functions/get_the_author_meta/

And send the email:
https://developer.wordpress.org/reference/functions/wp_mail/

#1912353

Hi Luo

Sorry for my late reply.

So to send an email to the parent_post author I added following in my functions.php

// Send an email when two posts are connected in a specific post relationship
add_action( 'toolset_association_created', 'tssupp_rel_send_on_create', 10, 5 );
function tssupp_rel_send_on_create( $association_slug, $parent_id, $child_id, $intermediary_id, $association_id ) {
// only trigger this notification for the 'zoek-paard' post relationship slug
if( $association_slug == 'zoek-paard' ) {
$author_id = get_post_field ('post_author', $parent_post_id);
$to = get_the_author_meta( 'user_email', $author_id );
$subject = "A new horse added for your search";
$headers = array("Content-Type: text/html; charset=UTF-8");
$parent_title = get_the_title( $parent_id );
$child_title = get_the_title( $child_id );
$body = "The following two posts have been connected in the " . $association_slug . " post relationship: <br />";
$body .= "a new horse was added to your search: " . $child_title;
wp_mail( $to, $subject, $body, $headers );
}

If I replace $to = get_the_author_meta( 'user_email', $author_id ); by $to = "my_email"; it seems to work. How can I now make sure it sends to the parent post author email?

#1912361

My issue is resolved
I didn't define post author