Ad 468 X 60

Sunday, 25 May 2014

Widgets

Send email to users on post publish with acf plugin custom fields

Dear users,
Today we are talking about sending email when a post is published.As i search on Google for this snippet ,I found many script to done this job but mostly did not work properly  and when i worked  on it ,its successfully sent the email to users..
So there are many  Hooks available for do this job  and these are called  'Actions', Each action takes the form of '{$old_status}_to_{$new_status}'.
These actions are
1) publish_post
2) save_post,
3) draft_to_publish
4) transition_post_status
for more action please visit  WordPress Codex Source



function my_function($post_id) {
$post = get_post($post_id);
$author = get_userdata($post->post_author);

$message = "
Dear ".$author->display_name.",
Your post, ".$post->post_title." has just been published at&nbsp
".get_permalink( $post_id ).". Well done!
";
wp_mail($author->user_email, "Your article is online", $message);
}
add_action('publish_post', 'my_function');

// or for default use

add_action('acf_save_post', 'my_function');
// if use acf (Advance Custom Field ) plugin and wordpress version should be 3.x
// or wordpress version is 4.x then use it

add_action('acf/save_post', 'my_function');


"publish_post" will send email first time
"save_post" will send email every click on update the post

But if you want send email with Acf plugin fields then you have to use Acf action "acf_save_post"
because of acf plugin work just after publish the post and you can not get the field value of acf in publish_post action.so you  have to use "acf_save_post" for version(3.x) and version(4.x) you have to use "acf/save_post"   for more acf action details please visit the   Acf action





SHARE THIS POST   

  • Facebook
  • Twitter
  • Myspace
  • Google Buzz
  • Reddit
  • Stumnleupon
  • Delicious
  • Digg
  • Technorati

1 comment: