Skip to content

Instantly share code, notes, and snippets.

@k33
Created January 26, 2016 10:29
Show Gist options
  • Save k33/89447a25b482033ad14a to your computer and use it in GitHub Desktop.
Save k33/89447a25b482033ad14a to your computer and use it in GitHub Desktop.
This adds ACF content to the posts content if it is called by the feed.
// This adds ACF content to the posts content if it is called by the feed.
// SRC: https://digwp.com/2012/10/customizing-wordpress-feeds/ AND http://www.paulund.co.uk/add-custom-fields-to-rss-feed
function fields_in_feed( $content ) {
if( is_feed() ) {
$post_id = get_the_ID();
$acf = get_post_meta( $post_id, 'newsletter-posts-specific', true ); //using 'true' here is vital
$output = '';
if ( $acf ) {
$output .= '<div class="newsletter-posts-specific">';
$output .= '<br /><h2>In this edition</h2><br />';
// Loop through the ACF relationship field
foreach ( $acf as $acf_post_id ) {
$excerpt = apply_filters( 'the_excerpt', get_post_field( 'post_excerpt', $acf_post_id ) );
$image = get_the_post_thumbnail( $acf_post_id, 'large' );
$output .= $image;
$output .= '<br /><h3>' . get_the_title( $acf_post_id ) . '</h3>';
$output .= $excerpt;
$output .= '<a href="' . get_permalink( $acf_post_id ) . '">read more...</a><br /><br />';
} // End ACF loop
$output .= '</div>';
} // End if ACF
$content = $content.$output;
} // End if feed
return $content;
} // End function
add_filter('the_content','fields_in_feed');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment