Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5955883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:10:39+00:00 2026-05-22T18:10:39+00:00

In WordPress, I have added a custom field on my posts page called post-expiry

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:10:39+00:00Added an answer on May 22, 2026 at 6:10 pm

    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:

    <?= time() > strtotime( $post-expiry ) ? 'expired' : '' ?>
    

    strtotime() turns a string into a unix timestamp, and time() 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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have added a field in wordpress posts table named parent_location. How to get
I have wordpress site, i added like button for share post. But, i don't
I have a wordpress website which I've added a couple of custom pages to.
I wanted to use the custom field for wordpress to have a different header
I have a WordPress site (2.6.2) in which I have set the Home page
I am working in a MySQL database. I have added a custom field to
I have a drop-down menu that are dynamically added through WordPress. It looks like
I have an ASP.NET site which I'd like to add page-level comments to without
I have a wordpress theme that I like to duplicate. To make things easier
I have a fairly complex WordPress + bbPress installation and I would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.