I will try to explain my issue as good as i can. Please take a look at the following page in my website.
We have:
- The main page
- Inside the main page there is a "view offer" button
- The "view offer" button links to a post.
- The post has an expiration date (done through a plugin)
- Underneath the "view offer" button there is a "valid until" field
What i am trying to achieve is the following:
I would like to get the post ID behind the link automatically, use the post ID to get the post's expiration date and then display it next to the "valid until" field automatically. I can already achieve this but i would like to be a bit more automated. Here's the code i am using so far:
<?php
$postid = 4407;
$date_format = __( 'd / m / Y' );
$expiration_date = get_post_meta( $postid, '_expiration_date', true);
if (get_post_status($postid)=='publish')
echo date_i18n( $date_format, strtotime( $expiration_date ) );
?>
My problem with the above code is that it's only valid if i already know the Post ID number and since i have many pages and posts, i would have to create different code for each page and post. I would like to create a single code that could apply to all of my pages. So basically, i would like to grab the post ID automatically based on the link behind the "view offer" button.
As for how i am using PHP, i have a plugin that allows me to create PHP code snippets and then use them anywhere i like as shortcodes. Therefore, i have a shortcode with the PHP code above next to "valid until" field.
I'm not sure that is possible or if my approach to begin with is wrong but any help would be highly appreciated.
Regards, Charis