Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Post Expiry - Add Term WordPress

  • SOLVED

I am trying to create a function to expire a post from a custom post type on a given date.

The date is given via a custom field called 'expiry' in the format dd/mm/yyyy OR mm/dd/yyyy (this can be changed if needed).

Upon expiry I want to add a term from the taxonomy 'tags' called 'expired' - but nothing else should happen - the post needs to stay live.

Is there a way to do this?

Answers (3)

2012-01-16

Francisco Javier Carazo Gil answers:

Robster,

You can do the next:
1. Create an action: add_action( 'init', 'update_expired' );
2. Create a function "update_expired" that UPDATE the post and include this tag


Francisco Javier Carazo Gil comments:

The function should do something like this:
1. Select all posts that are not expired
2. Foreach post -> get the meta value and compare with current date
3. If comparison is true, include the tag

If you want the code, send a me a PM and I will do it for you. We can publish it here later.


Francisco Javier Carazo Gil comments:

In order to increase the number of available options, I have modified plugin post-expirator.

What have I done with plugin? I have modified to make it set tag "expired" (append tag, not remove all and insert only it) in post that should expire. Now, when you select "Delete" you are choosing set tag "expired".


robster comments:

Great solution! Thanks Javier!

2012-01-16

Alberto Hornero Luque answers:

You can use [[LINK href="http://wordpress.org/extend/plugins/post-expirator/"]]Post Expirator Plugin[[/LINK]]. It's very useful.

Regards.


robster comments:

Thanks Alberto, but it doesn't appear to have the ability to expire and add a tag at the same time...

2012-01-16

Arnav Joy answers:

I think this work needs custom work , I am ok with it send me a PM ,if you are intrested.

Thanks