Hi Nigel
I posted a post yesterday at 15:30 (at front end):
Start date and time: same day time 16:00
End date and time: same day time 16:30
Could it be that it is not placed because the time is too short? Perhaps with regard to the cron job interval?
Yesterday I saw the post not visible on the website, for example on the homepage. Also the test post toolset does not.
I will try again today and let you know as soon as possible.
Thanks in advance,
Greetings Pascal
Hello Nigel
I just posted a post via the front end:
Titel: “Limonade Test offer Pascal”
Date and start time: Today 08/08 time 16:00
Date and end time: Today 08/08 time 17:00
I see on the backend the following:
Date and start time: Today 08/08 time 16:00 (same = ok)
Date and end time: Today 08/08 time 17:00 (same = ok)
Expiration of the post is showing: 08/08 19:00
The expectation:
1) The post will be displayed at various locations on the front end, for example the main page and page offers (aanbiedingen) and my account page (my offers - mijn aanbiedingen).
2) The post wil automatically be delete after 19:00.
Let's wait until 16:00 (Dutch time) and look wat will happen.
keep fingers crossed 🙂
Hello Nigel
The post has not been published at 16:00
When I look in the back end, I see the post is still scheduled, nothing is shown on the front end of the website.
Hello Nigel
I wonder if using WP Cron this is stable enough, I understand that when there are several CRON jobs at the same time that problems can arise (We do not want to miss any posts).
Let's review what we want exactly, to be sure, we may be doing too much work:
- A post (offer) may be placed directly (visible on the website must be the start date and end date) this was also the case at first.
- When creating the post is also chosen an end date and end time (this is the End date and time until when the offer is valid).
- Through the post changing form a user can change the offer, also the end date and time.
The post must be automatically deleted as soon as possible after the chosen End date and end time (for example Enddate + time + 2 hours or if not possible the day after the end date).
Is there maybe another way to do this? Or do you still think the best way is to get the Cron Job working?
Greetings Pascal
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
Cron jobs are the way to go, there isn't really an alternative, but this should be working, I have something similar (not exactly the same) on my test site and it is working okay.
I noticed that your settings are to run the cron job only once a day (screenshot). You probably want to change that to hourly, go to Toolset > Settings > Forms.
I'm not sure why the scheduled post isn't appearing as published once the publication date/time has passed.
There could be a discrepancy relating to timezones, I'll take a look in the morning.
Hi Nigel
I start my computer in the evening and saw that the post that I posted earlier that afternoon was on the website.
I was surprised and at the same time enthusiastic. I have read your message and the CRON settings were indeed on 1x per day. When I changed this to 1 x per hour the postl disappeared immediately.
I have adjusted the CRON setting again to 5 minutes and create a new post.
Title: Test pascal Bread Date 08/08 time 20:45 End date 08/08 end time 21:00
But the post is not shown on the website yet, the time it is now 21:27
Just a question, not meant wrong but how stable is CRON?
I want to be sure that I will not have any problems in the future regarding posting and deleting posts.
The user of the website has paying customers.
If it is not stable and it is better to manually remove the posts then I will have to discus this with the user.
I did not expect it to be so complicated.
You do a really fantastic job, I'm waiting for your message
Greetings Pascal
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
Hi Pascal
I did some more testing and I found a couple of typos and also I confirmed that there was an issue relating to timezone settings.
I updated the code to the following:
/**
* Set custom expiry date based on form field
*/
function tssupp_custom_expiry( $post_id, $form_data ){
$begins_field = 'wpcf-startdatum-aanbieding';
$expires_field = 'wpcf-einddatum-en-tijd-aanbieding';
$offset_hours = get_option( 'gmt_offset' );
$offset_secs = $offset_hours * 60 * 60;
if ( in_array( $form_data['id'], array( 349, 885 ) ) ) {
if ( isset( $_POST[ $expires_field ] ) ) {
$expires = $_POST[ $expires_field ]['timestamp'];
$expires_gmt = $expires - $offset_secs;
update_post_meta( $post_id, '_cred_post_expiration_time', $expires_gmt );
}
if ( isset( $_POST[ $begins_field ] ) ) {
$begins_timestamp = $_POST[ $begins_field ][ 'timestamp' ];
$begins = date('Y-m-d H:i:s', $begins_timestamp );
$begins_gmt = date('Y-m-d H:i:s', ( $begins_timestamp + $offset_secs ) );
wp_update_post( array
(
'ID' => $post_id,
'post_date' => $begins,
'post_date_gmt' => $begins_gmt
)
);
}
}
}
add_action( 'cred_save_data', 'tssupp_custom_expiry', 10, 2 );
I tested this locally and it worked very much as expected, so hopefully if you make some new test posts you should see everything working fine too.
(I'm stopping now for a few days holiday, so if you have a new issue with this you may want to start a new thread so a colleague can help you.)
Unfortunately it did not work out. When a post is placed it does not appear on the website at the set time.
I decided to leave it for what it is, the project must be completed as soon as possible. Perhaps we will be able to find out this later on a test domain.
Thank you in any case for the work and help you have done.
Have a nice holiday
Greetings Pascal