It is a very common situation:I've three groups: Past, Current, Approaching.

Now I write a publish about next month's event. I put this publish in Approaching category.

Things I want is really a scheduled category change.

i.e.:

The wedding runs from 12 , 1 to 12 , 10. From now till November 30, this publish is within Approaching category (I choose this category when designing this publish).

On 12 , 1, this publish come in Current category instantly, till 12 , 10.

On 12 , 11, this publish come in Past category instantly.

Used to do searching and didn't find such plug-in.

Essentially, I would like the posting page to possess two extra options:

Option 1: Switch to Category _ on _

Option 2: Switch to Category _ on _

It may sound just like a workflow question. I looked workflow related wordpress plugin but nonetheless without any luck.

Any suggestion regarding how to implement this? I'm able to write a wordpress plugin however i am a new comer to Wordpress. Could anybody suggest me which API/functions to make use of?

Thanks!

To begin with: There might be a wordpress plugin available that may handle what you would like to attain. Should you prefer a simple occasions calendar, I'm almost certain you can do this with existing plug ins. Off the top my mind, MyCalendar could be one particular wordpress plugin. You might like to search the wordpress plugin directory for more options, before you decide to dive into coding this by yourself.

That being stated, if you cannot avoid creating this yourself, because you are situation would be to specialized, this will enable you to get began:

Either use custom fields to include the additional meta-data of start and finish date or result in the occasions a custom post type that belongs to them. Explaining using custom publish types en detail is beyond the scope of the concise SO answer.

If you go searching for the more method of adding two custom fields known as start and finish (or even the like), you'll have to either operate a php script like a cronjob via your server or make us from the WP-Cron Functions to check the present time using the start and finish date and alter the course accordingly.

To offer you some helpful code (which may get into oneself-written wordpress plugin), the next php snippet should point you within the right direction:

register_activation_hook(__FILE__, 'your_activation');
add_action('your_daily_event', 'change_categories');

function your_activation() {
    $first_time = time(); // you probably want this to be shortly after midnight
    $recurrence = 'daily';
    wp_schedule_event($first_time, $recurrence, 'your_daily_event');
}

function change_categories() {
    $old_name = 'Upcoming'; // category to delete
    $taxonomy = 'category';
    // fetch category ID (amongst other data) of 'Upcoming':
    $term = get_term_by('name',$old_name, $taxonomy);
    // fetch all posts in 'Upcoming' category:
    $objects = get_objects_in_term($term->term_id,$taxonomy);
    // the $objects array now contains the post IDs of all upcoming events

    // now, let's loop through them to manipulate:
    foreach($objects as $object) {
         // get start date:
         $key = 'start'; // the name of the custom field
         $start = get_post_meta($object, $key, true); // start date
         $todays_date = date('Y-m-d'); // get current date
         // Assuming, your dates in the custom fields are formatted YYYY-MM-DD:
         if ($start < $todays_date) {
             // change category:
             $new_name = 'Current';
             wp_set_post_terms( $object, $new_name, $taxonomy, false );
         }
    }

?>

Couple of notes:

  • The above mentioned would need to be changed for that vary from "Current" to "Past", clearly.
  • It may be easily modified to incorporate time too.
  • The cronjobs should initiate soon after night time
  • $first_time needs to be considered a UNIX timestamp
  • Look into the wordpress function reference for additional info on the wordpress functions used above