admin管理员组文章数量:1421223
I am designing a website intended to list local events. Ideally registered users would be able to upload new events from the front end and the website would display all the upcoming events in chronological order.
I have registered an "Event" custom post type, as a first step, with several custom fields (category, date, time, etc.).
Now I am creating a cron job that loops through the events hourly and removes the ones that have expired.
Finding the events to remove is an easy task.
1) The cron job gets the current date, firstly:
$currentdate= date("Y-m-d");
2) It then gets the starting date of the event (stored in a custom field):
$eventdate = get_field('date');
3) And compares the two with a simple conditional statement:
if ($currentdate > $eventdate ) do something
At this point I would like to make it so that the cron job changes the post type of the expired events to a completely different one - I reckon it would be the best approach (the amount of active events wouldn't progressively increase with time, this way).
My question is then: is there a way to tell Wordpress to change the post type of a post into another?
Thanks in advance for your help :3
I am designing a website intended to list local events. Ideally registered users would be able to upload new events from the front end and the website would display all the upcoming events in chronological order.
I have registered an "Event" custom post type, as a first step, with several custom fields (category, date, time, etc.).
Now I am creating a cron job that loops through the events hourly and removes the ones that have expired.
Finding the events to remove is an easy task.
1) The cron job gets the current date, firstly:
$currentdate= date("Y-m-d");
2) It then gets the starting date of the event (stored in a custom field):
$eventdate = get_field('date');
3) And compares the two with a simple conditional statement:
if ($currentdate > $eventdate ) do something
At this point I would like to make it so that the cron job changes the post type of the expired events to a completely different one - I reckon it would be the best approach (the amount of active events wouldn't progressively increase with time, this way).
My question is then: is there a way to tell Wordpress to change the post type of a post into another?
Thanks in advance for your help :3
Share Improve this question asked Jul 3, 2019 at 16:54 Campioni Del MondoCampioni Del Mondo 31 bronze badge1 Answer
Reset to default 2You can use Function Reference/set post type
<?php
$post_id = 15;
if ( set_post_type( $post_id, 'page' ) ) {
echo "Post #$post_id is now a Page";
} else {
echo "Impossible to transform this post into a page";
}
?>
本文标签: wp cronConvert post type to another
版权声明:本文标题:wp cron - Convert post type to another 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745348040a2654590.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论