Support » Plugin: iCal Feeds » Added Custom field for date support

  • ResolvedPlugin Contributor contemplate

    (@contemplate)


    Thanks so much @n00bie12 in this thread for the initial solution. I’ve created a small addition which I hope can be included in the core. I’ve updated the code so that it can grab any custom field in the Post Meta table without the need of the ACF plugin to grab the field.

    This will allow for any feed to have a custom “datefield” variable to be added like so:
    http://yourdomain.com/?ical&datefield=event_date

    Edit file: ical-feeds.php

    around line 194 add:

    
    	echo '<h2>'.__('Custom Date iCal feed', ICALFEEDS_TEXTDOMAIN).'</h2>';
    	
    	echo '<p>'.__('You can use a custom date field instead of the deafult publish date. The Meta Key must exist in the Post Meta table.', ICALFEEDS_TEXTDOMAIN).'</p>';
    	
    	echo '<p>Example Date meta_key: "event_date"  <a href="'.site_url().'/?ical&datefield=event_date" target="_blank">'.site_url().'/?ical&datefield=event_date</a></p>';
    

    then around line 246 add:

    
    	$post_date_field = 'pubDate';
    	if (isset($_GET['datefield'])) {
    		$post_date_field = $_GET['datefield'];
    	}
    

    finally around line 310 replace this:

    
    $start_time = date( 'Ymd\THis', get_post_time( 'U', false, $post->ID ) );
    $end_time = date( 'Ymd\THis', get_post_time( 'U', false, $post->ID ) + ($options['icalfeeds_minutes'] * 60));
    

    with this:

    
    if ($post_date_field != 'pubDate'){
           $start_time = date( 'Ymd\THis', strtotime( get_post_meta( $post->ID, $post_date_field, true ) ) );
           $end_time = date( 'Ymd\THis', strtotime( get_post_meta( $post->ID, $post_date_field, true ) ) + ($options['icalfeeds_minutes'] * 60));		
    } else { 
           $start_time = date( 'Ymd\THis', get_post_time( 'U', false, $post->ID ) );
           $end_time = date( 'Ymd\THis', get_post_time( 'U', false, $post->ID ) + ($options['icalfeeds_minutes'] * 60));
    }
    

    Hope that helps!

    • This topic was modified 2 years, 4 months ago by contemplate.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Added Custom field for date support’ is closed to new replies.