HTML code in Custom field

I’m using a custom field to display images in a slider on each post, but when I update the post after having entered the HTML code in the custom field, the code disappears. I’m assuming that there is some kind of filter that removes HTML code from custom fields when a post is saved. Is there a way to circumvent that without using a plugin?

Thanks!

Read More

Edit: The information is saved using the following code:

function save_details(){
    global $post;

    update_post_meta($post->ID, "ptime", $_POST["ptime"]);
    update_post_meta($post->ID, "services", $_POST["services"]);
    update_post_meta($post->ID, "tools", $_POST["tools"]);
    update_post_meta($post->ID, "url", $_POST["url"]);
    update_post_meta($post->ID, "images", $_POST["images"]);
}

You can find the complete functions.php code here (Pastebin).

Related posts

Leave a Reply

1 comment

  1. UPDATED ANSWER

    The correct function to use in context to WordPress and its intended API for this purpose is;

    esc_textarea

    Thus your code would reflect something like this;

    <textarea><?php echo esc_textarea($images);?></textarea>
    

    Although htmlspecialchars and htmlentities are valid to use, and even though esc_textarea wraps htmlspecialchars anyway, its more appropriate to use the official API call.

    I’ve left my original answer below for reference purposes, however swap out the relevant functions as needed.

    ORIGINAL ANSWER

    In your snipped at Pastebin replace your images_box function with (start of line 65);

    function images_box($echo = FALSE){
      global $post;
      $custom = get_post_custom($post->ID);
      $images = $custom["images"][0];
      ?>
      <textarea name="images" cols="100" rows="10">
    
          <?php echo htmlspecialchars($images); //Hi, I'm your input! ?> 
    
      </textarea>
      <?php
    }
    

    You were not echoing the value of your input between the <textarea> ECHO INPUT HERE </textarea> tags thus it appears you were not entering anything at all.

    Also wrap your input with htmlspecialchars

    Also $city = $custom["images"][0]; should be $images = $custom["images"][0]; (line 68)