简体   繁体   English

修改 Wordpress RSS Feed 的内容

[英]Modifying content of Wordpress RSS Feed

I am trying to move the custom field <rule_short_summary> into the field <content:encoded> so I may display it in an automated newsletter.我正在尝试将自定义字段<rule_short_summary>移动到字段<content:encoded>中,以便我可以在自动通讯中显示它。

This is what I have:这就是我所拥有的:

function my_add_to_content($content) {
  $post_id = get_the_ID();
  $rule_short_summary = get_the_terms($post_ID, 'rule_short_summary');
    return  $rule_short_summary;
}
add_filter('the_content_feed', 'my_add_to_content');

Currently content:encoded returns an empty field.目前 content:encoded 返回一个空字段。

I am taking inspiration from this link: http://https//digwp.com/2019/09/add-content-wordpress-feed/ In this link, the author adds custom text to the content.我从这个链接中获得灵感:http://https//digwp.com/2019/09/add-content-wordpress-feed/ 在这个链接中,作者在内容中添加了自定义文本。 I want to pull from another field and add to the content.我想从另一个字段中提取并添加到内容中。

Custom fields can be called using get_post_meta function.可以使用 get_post_meta function 调用自定义字段。 In your given code you have use get_the_terms function - which is wrong for this case of course.在您给定的代码中,您使用了 get_the_terms function - 这对于这种情况当然是错误的。

function my_add_to_content($content) {
  $post_id = get_the_ID();
  $rule_short_summary = get_post_meta($post_ID, 'rule_short_summary',true);
    return  $rule_short_summary;
}
add_filter('the_content_feed', 'my_add_to_content');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM