[英]How to add custom field to a post RSS title in Wordpress
I found a topic about how to add categories to a wordpress rss feed, but how is it possible to add a custom field to a wordpress RSS feed titel? 我找到了一个有关如何向wordpress rss feed中添加类别的主题,但是如何向wordpress RSS feed标题中添加自定义字段呢?
function rssTitle_add_categories($title) {
$category_array = array_map(create_function('$category', 'return $category->name;'), get_the_category());
$categories = join(', ', $category_array);
$title = $title . ' - '.$categories.' - ';
return $title;
}
add_filter('the_title_rss', 'rssTitle_add_categories');
You just have to get your custom field using get_post_meta
(or plugin API if you are using a custom fields plugin) and add it to your title, for example : 您只需要使用get_post_meta
(如果使用自定义字段插件,则使用插件API)来获取自定义字段,并将其添加到标题中,例如:
function rssTitle_add_categories($title) {
global $wp_query;
$category_array = array_map(create_function('$category', 'return $category->name;'), get_the_category());
$categories = join(', ', $category_array);
$field = get_post_meta($wp_query->post->ID, 'your_field_name', true);
$title = $title.' - '.$categories.' - '.$field;
return $title;
}
add_filter('the_title_rss', 'rssTitle_add_categories');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.