How to change text (date) in post base on the day

Here’s summed up what you need to do:

  • Get a meta box library.
  • Add custom fields with dates
  • Attach a filter callback action to the_content filter
  • Get the current date, check your custom fields, append date in content.

So here’s the filter callback, that lets you append your “next date”:

function wpse66615_date_to_content( $content )
{
    $dates[] = get_meta_custom( get_the_ID(), 'THE_KEY/NAME_YOU_ADDED', true );
    $dates[] = get_meta_custom( get_the_ID(), 'ANOTHER_KEY/NAME_YOU_ADDED', true );
    // $date_c = ...

    // We need the current time to compare (UNIX timestamp)
    $today = current_time( 'timestamp' );

    foreach ( $dates as $key => $date )
    {
        // Now get rid of all dates that already passed
        if ( $today > strtotime( $date ) )
            unset( $dates[ $key ] );
    }

    // We really ran out of dates...
    empty( $dates ) AND $dates[] = 'There is really no date left';

    // Then take the first array item from our left dates
    $next_date = array_shift( $dates );

    // Then we append it to the content
    return $content."<br /><strong>Next date:</strong> ".$next_date;
}
add_filter( 'the_content', 'wpse66615_date_to_content' );

When you now call the_content(); or apply_filters( 'the_content', get_the_content() );, then you’d get an output like the following:

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.

Next date: d-m-Y