Hello,
Im trying to add ACF image URL to my RSS feed with the following code in functions.php:
<?php
function fields_in_feed($content) {
if(is_feed()) {
$post_id = get_the_ID();
$output = '<acfTitle>' . get_post_meta($post_id, 'titel', true) . '</acfTitle>';
$output .= '<acfImage>' . get_post_field($post_id, 'img', true) . '</acfImage>';
$output .= '<acfText>' . get_post_meta($post_id, 'text', true) . '</acfText>';
}
return $output;
}
add_filter('the_content','fields_in_feed');
?>
The title and text returns just great but the img just output the width of the image. I want the URL of the image.
How do I accomplish this?
Hi @Dev
The problem is that you are using the get_post_meta function instead of the ACF get_field function.
Please refer to the image field docs on how to render the image URL
http://www.advancedcustomfields.com/resources/field-types/image/
Thanks
E
i was trying to get acf content in general to show the text for items.
in the rss feed which i used in a mailchimp campagne it was only showing the title as a link to the item.
when i put the code above in the functions.php it seemed to work but the content of my pages (without acf fields, only the ‘content’) disappeared.
any thoughts?
o wait, thsi seems to work:
function fields_in_feed($content) {
if(is_feed()) {
$post_id = get_the_ID();
$output .= '<p>' . get_post_meta($post_id, "text", true) . '</p>';
$content = $content.$output;
}
return $content;
}
add_filter('the_content','fields_in_feed');