Skip Navigation

[Resolved] Try to create an email list with the help of "toolset_get_related_post"

This support ticket is created 3 years, 3 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
- 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 1 reply, has 2 voices.

Last updated by Luo Yang 3 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1901803

Tell us what you are trying to do?

I try to create an email list as a shortcode with the help of "toolset_get_related_posts". The emails are stored in the parent posts of a related childpost. Through $id I can access the id of the child.

But somehow $child_posts does not return any results.

add_shortcode( 'email_liste', 'func_email' );

function func_email ( $atts ){

extract( shortcode_atts( array('id' => '', ), $atts ) );
  
//post_id
$id = $atts['id'];
   
$child_posts = toolset_get_related_posts($id,'selbstportrat-reitanlagen','child',999,0,array(),'post_id','parent');
 
   
//if it returns some posts
        if( $child_posts){
  

$emails = "Test , ";
  
            //now get the single posts fields values 
            foreach( $child_posts as $single_post ){ 
   
                //get each Posts post data
                $single_post_data = get_post($single_post);
                //get each ID
                $single_post_id = $single_post_data->ID;
                                //get each posts field value
  
  
$email = get_post_meta($single_post_id, 'wpcf-covid-19-benutzerprofil-e-mail', true);
   
//we need to create a list BEFORE the if is closed and BEFORE the foreach is closed

$emails .=  $email . ',';

}

 
// Ignore duplicates
$emails = array_unique( $emails );            
        
           
}  
  
  
return $emails;
  
}

Is there any documentation that you are following?
https://toolset.com/forums/topic/post-relationship-query-with-toolset_get_related_posts/
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

Is there a similar example that we can see?
no

What is the link to your site?
hidden link

#1901983

Hello,

I suggest you debug the custom PHP codes line by line, for example:
Replace this line from:
//post_id
$id = $atts['id'];

With:
//post_id
$id = $atts['id'];
var_dump($id);

Make sure it is outputting the correct post ID value

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