最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Trigger WP CRON from a date in a Custom Field?

programmeradmin1浏览0评论

I have Custom Post Types which have a vanilla 'date-picker' for each post.

My Custom Posts are actually events that are always in the future.

I'd like to know if I can somehow trigger an alert when an event is over?

I am using a Custom Post Type plugin called "Pods" which is awesome.

Can anyone think of a way to make this happen?

Ideally, I'd have an email sent to me or to trigger a Zapier API call, or similar...

Any ideas on how to approach this?

Thanks!

I have Custom Post Types which have a vanilla 'date-picker' for each post.

My Custom Posts are actually events that are always in the future.

I'd like to know if I can somehow trigger an alert when an event is over?

I am using a Custom Post Type plugin called "Pods" which is awesome.

Can anyone think of a way to make this happen?

Ideally, I'd have an email sent to me or to trigger a Zapier API call, or similar...

Any ideas on how to approach this?

Thanks!

Share Improve this question asked Jul 19, 2019 at 8:53 HenryHenry 9831 gold badge8 silver badges31 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You will have to write a plugin which creates a daily cron job in the WordPress system.

Here's an article describing how to write a cron plugin:

https://wpguru.co.uk/2014/01/how-to-create-a-cron-job-in-wordpress-teach-your-plugin-to-do-something-automatically/

The function (callback) that you trigger in the cron plugin will use WP_QUERY to get a list of all your published custom post types after a certain date.

e.g.

$my_query = new WP_Query( array(
    'post_type' => 'your-cpt-name-here',
    'order' => 'ASC',
    'posts_per_page' => 1,
    'date_query' => array(
        array(
            'after' => '1 day',
        )
    ),
) );

Run through the results and send an email using wp_mail().

Alternatively, ask on fiver and get a developer to do it for you. It's pretty simple so won't cost very much at all.

发布评论

评论列表(0)

  1. 暂无评论