Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

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).

share|improve this question
1  
No, there is no such filter by default. How is the field saved? Add this information to your question to make answers possible. –  toscho Jul 7 '12 at 13:25
1  
Updated the main post. –  Anders Norén Jul 7 '12 at 13:31
add comment

1 Answer

up vote 1 down vote accepted

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)

share|improve this answer
    
That did the trick, thanks! –  Anders Norén Jul 9 '12 at 8:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.