I am using this code to send an email from my wordpress site. It send permalinks of the posts. How can i edit this to have linked titles instead of just permalinks;

if(count($ids) > 0){
                $user_id = $usermeta['user_id'];
                $userdata = get_userdata($user_id);
                $email = $userdata->data->user_email;
                //echo $email;
                $links = '';
                foreach($ids as $id){
                    $link = get_permalink($id);
                    $links .= $link . ' <br>';
                //echo $links;

                if (have_posts()) : 
                    while (have_posts()) : 
                        $emailTpl = get_the_content();

                $message = preg_replace('/\[\%urls\%\]/', $links, $emailTpl);
                $headers = "MIME-Version: 1.0\n" . "Content-Type: text/html;"; 
                //wp_mail('ehmudroy@gmail.com', 'New project notification', $link);
                //wp_mail('lijb@stunningtech.com', 'New project notification', $message, $headers);
                wp_mail($email, 'New project notification', $message, $headers);

Did you use it like that??

<a href="<?php get_permalink($id); ?>"><?php the_title($id); ?></a>

for use to that

foreach($ids as $id){
  $link = get_permalink($id);
  $title = get_the_title($id);
  $links .= '<a href="'.$link.'">'.$title.'</a>'.'<br/>' ;
  //$links .= $link . ' <br>';



Try to use that while I'm coding your code.

| improve this answer | |
  • Did you have a chance? – yeshansachithak Apr 15 '14 at 11:41
  • @Ahmad Good man. Have a good day. :-) :-D :-) – yeshansachithak Apr 16 '14 at 4:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.