php - Change category of wordpress post when date is today


So I am using the plugin 'the future is now' on a wordpress site, the site is for event news, once an event has happened i need it to move into from the 'events' category to the 'results'.

The plugin 'the future is now' takes care of displaying future posts but I cannot find anything online as to how to change the post category when the date is 1 day past.

For example an event on the 11/04/2014 should change categories at 00:01 12/04/2014.




You will need a couple things in order to change the category using PHP

  $date = the_date();
  $today = date("F j, Y");
  if($date < $today){
    $post_ID = get_the_ID(); 
    $post_categories = array(CATEGORY_NUMBER_FOR_RESULTS);   
    wp_set_post_categories( $post_ID, $post_categories );

You will need to place this in the while-loop you use to get the "Events" category posts. While this method should work I highly recommend NOT using it because if at any point the post_ID or post_categories messes up it can create orphan posts which will need SQL database manipulation to fix.

People are also looking for solutions to the problem: xml - Php Code (Get/Fetch Kongregate Games)


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.