Miuranga
Miuranga

Reputation: 2463

Wordpress RSS feed not work when custom filed have '&'

WordPress RSS feed not work when custom filed have '&'. i think that may be XML error with character '&'. How could I change to that & to '&amp' in custom field in wp-php code or any working way? Error !! I am using following code

function customFieldFilter($id) {
$meta = get_post_meta($id);
foreach ($meta as $key => $value) {
   update_post_meta($id, $key, esc_attr($value));
}

} add_action('pre_post_update', 'customFieldFilter');

Upvotes: 0

Views: 181

Answers (1)

turbonerd
turbonerd

Reputation: 1306

When you're saving your custom field, try wrapping it in the esc_html WordPress function.

I'm not sure exactly how you save your custom fields, as you haven't provided any code, but for me this would be something along the lines of:

$habitat = esc_html( $_POST["habitat"] );
update_post_meta( $post->ID, "habitat", $_POST["habitat"] );

However, I would really like to see the way you're saving your custom fields as I believe that esc_html should be run by the update_post_meta function?


EDIT

Try adding this to your theme's functions.php (right at the bottom):

function custom_field_filter( $id ) {
    $meta = get_post_custom( $id );
    foreach ( $meta as $key => $value )
        update_post_meta( $id, $key, esc_html( $value ) );
}

add_action('pre_post_update', 'custom_field_filter', 100);

This is pure guess-work I'm afraid, I really can't find a lot of information on custom fields. This should retrieve all of the custom fields attached to the post, on save, and run them through a function to encode the & character to & which will hopefully fix your RSS feed.

Upvotes: 1

Related Questions