Support » Fixing WordPress » Looking for specific functionality

  • I need to create a daily email that shows a link to all of the posts posted that morning.

    For instance, the client posts 5 new posts every day. I need to have an email that shows a link to all 5. This email should be sent shortly after all 5 are posted.

    I am running a plugin which will post only one link to one post. It is working properly, and emails are going out and the cron fires, but does not fulfill my needs, as it only shows one link.


Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    It may or may not be feasible to hack the plugin so it returns all posts published in the previous day. Creating your own plugin that does this isn’t too complex if you can manage some PHP coding.

    You’d write a function that queries for all posts published in a certain period such as the last 24 hours. You can use WP_Query class for this. Your code then loops through the results much like any other WP loop, except the HTML is compiled into an email message instead of being output. Unless all of your content is plain text, use the “wp_mail_content_type” filter to set the email mime type to text/html.

    You then schedule your function to be called on a daily basis with wp_schedule_event(). Note that your function will not be called exactly on a 24 hour interval, so if you query for posts in the last 24 hours exactly, there’s a small chance a post or two could be missed. OTOH, if you query for posts in the last, say 25 hours, to compensate, there’s the chance you’ll get some redundant posts from email to email.

    You could store the timestamp of the current query as a transient, then use it to compose the next query’s date range. Then the results will always be correct, at the price of a little extra coding.

    Unless you’re familiar with coding WP modifications, this probably sounds hopelessly complex. If you focus on one specific, small task at a time, in the end you’ll find it’s all not nearly as bad as it sounds right now.

    Have you seen this: Email posts to subscribers

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Looking for specific functionality’ is closed to new replies.