In WordPress, I have added a custom field on my posts page called “post-expiry” in which I am enterting an expiry date formatted like this: “2011-04-28”.
Each post can have a different expiry date set. Once an expiry date passes, I want to apply a class to my post on the front end called “expired” which changes the visual style of the post.
Therefore, I need to devise a PHP function to sit within the WordPress Post Loop, that checks the date entered in my custom field meta, checks the actual date (perhaps checking with the web server or an internet time service) and then applies a class to the output if the date has passed.
Does anyone have any ideas about how I would code this function? I am still fairly new to PHP but I think its possible.
I am not sure what the wordpress variable names are (you will need to look that up :p), but here is how to function would look:
strtotime()turns a string into a unix timestamp, andtime()gets the server time’s unix timestamp.The function can be put right into the
class=" "part of whatever element you want it applied in.Hope this helps