wordpress feed增加自定义字段

直接在functions.php里面,追加自定义字段到feed item里面。


function fix_for_360_rss2_item() {
    $fields = array('_addlink_info_gglink');
    $post_id = get_the_ID();
    foreach($fields as $field){
        if ($value = get_post_meta($post_id,$field,true)){
            if($field == '_addlink_info_gglink'){
                $field = 'packagename';
                preg_match('/id=(.*)&/', $value, $r);
                if($r && !empty($r[1])){
                    echo "<{$field}>\n";
                }
            }
        }
    }
}
add_action('rss2_item', 'fix_for_360_rss2_item');


你可能感兴趣的:(php,wordpress)