Created
January 26, 2016 10:29
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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