hmmmm I have found this snippet but this will show not a right date:
<?php echo get_post_meta( get_the_ID(), '_expiration-date', true); ?>
For a test I have set the expire date of 21.09.2023 but in the table there are:
1695331200
Ahhhhhh
<?php echo do_shortcode('[postexpirator type=date]'); ?>
🙂 Thx for help 🙂
Hi @janwill
I’m glad your found the solution already.
For other users that facing the same issue, this is relevant documentation: https://publishpress.com/knowledge-base/shortcodes-to-show-expiration-date/
Thanks,
thxy 🙂
But I have another question:
I´m planning to change the category by a date from your plugin – thats fine and ist working. Now, after change the category, Im planning to show the posts, after a certain time, on another page with another WP_Query-Loop and order (‘meta_key’ => XXX) this posts with the expired date before.
But I can´t find the expired date in the table AFTER the plugin is change the category…
DO you know what I mean and do you can help me?
janwill
@janwill we don’t store the expiration date in the metadata after a post has expired, but you can use an action that is triggered when that happens, before the data is deleted. You could then grab the date and store in a different metadata.
You can try something like this:
add_action('publishpressfuture_post_expired', function ($postId) {
$actionDate = (int)get_post_meta($postId, '_expiration-date', true);
update_post_meta($postId, '_last_expiration_date', $actionDate);
});
Hi, many thx for help. This snippet worked well but I have another quistion for this:
How can I show the new custom field “_last_expiration_date” in the frontend like the field “_expiration_date”? For “_expiration_date” I use
[postexpirator type=date]
But how can I use this shortcode for the new custom fiel to show the date?
br
janwill
Hi there,
I could find a solution but I need one change in your code. How can I change your code
add_action('publishpressfuture_post_expired', function ($postId) {
$actionDate = (int)get_post_meta($postId, '_expiration-date', true);
update_post_meta($postId, '_last_expiration_date', $actionDate);
});
so the value of your custom field _expiration-date is copy to _last_expiration_date AND in another custom field _last_expiration_date_NEW but here with the right date output: d.m.Y H:i?
I need this for a custom query for the Plugin Search and Filter PRO, so I can filter the posts in the pasts… Do you can help me?
By the Way is it possible to change your custom field, so that the date is not save in UNIX but in normal date format, or is this to complex?
janwill
Hi @janwill
Cool, sure thing. You can try the following code. I left both formats, UNIX time, and your custom format. You can remove or customize according to your need.
add_action('publishpressfuture_post_expired', function ($postId) {
$actionDate = (int)get_post_meta($postId, '_expiration-date', true);
update_post_meta($postId, '_last_expiration_date', $actionDate);
update_post_meta($postId, '_last_expiration_date_NEW', gmdate("d.m.Y H:i", $actionDate));
});