0

I have this mail notification for new post.

All the new post contain arround 100 words and no pictures, so I would like to include in the notification the post content and if is possible, the number of words in the post.

Anybody could help me?

Thanks for all

    /* avisar al admin*/
function submit_send_email ($post) {

        $user_info = get_userdata ($post->post_author);
        $strTo = array ('mail@mail.com');
        $strSubject = 'Your website name: ' . $user_info->user_nicename . ' submitted a post';
        $strMessage = 'A post "' . $post->post_title . '" by ' . $user_info->user_nicename . ' was submitted for review at ' . wp_get_shortlink ($post->ID) . '&preview=true. Please proof.';
        wp_mail( $strTo, $strSubject, $strMessage );

}
add_action('future_to_pending', 'submit_send_email');
add_action('new_to_pending', 'submit_send_email');
add_action('draft_to_pending', 'submit_send_email');
add_action('auto-draft_to_pending', 'submit_send_email');
0

Use this function:

function word_count() {
    $content = get_post_field( 'post_content', $post->ID );
    $word_count = str_word_count( strip_tags( $content ) );
    return $word_count;
}

then call it to display the word count:

echo word_count();
  • Sorry, but this function won't work. You use $post->ID in your function, but it is not defined in that scope, so it will generate errors. – Krzysiek Dróżdż Sep 12 '18 at 19:19
0

I find better solution

function bavotasan_word_count() {
   return sprintf(
      __( '%s words', 'text-domain' ),
      str_word_count( strip_tags( get_post_field( 'post_content', get_the_ID() ) ) )
   );
}

to learn more how to use it function bavotasan_word_count()

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.