Please help! I have a form for users to submit posts, and I want them to be able to choose photos already in the media gallery based on category selected. I want to include radio buttons to choose between a few images that will attach to the post, become the featured image, or just echo out in a template file in this manner

    <?php $custommeta = get_post_meta($post->ID, "CategoryImage", true); ?> 

The value of the selected image will be the image url to echo out into the custom field.

I can not figure out the code to get the custom field in the form and get the value into the custom field. I think I should use add_post_meta but I am not completely sure how to incorporate it. Any help would be greatly appreciated.

I am using the plugin User Submitted Posts but I would take a general answer as well.

1 Answer 1


I got custom fields working in the front end form linked in this post:

How to use nonce with front end submission form?

Here is the code used for the form page (custom page template): http://pastebin.com/YWyXL3jY

Hopefully that will be of help to you with a bit of tweaking to use image URL's instead of text as the custom field input.

I had considered using the User Submitted Post plugin too but couldn't figure out how to include custom fields with that, so ended up making the form by hand.

  • Thanks jo_pinkish your code definitely helped me get it semi-working :-) ! The conditional statements I added aren't working however to show images based on category selected. I'm still working on that, if I figure it out I will post here for anyone else that needs help with this same issue. I also noticed that the form validation isn't working in your code. If you figure that out, along with the nonce thing can you let me know? Thanks so much. Your help is greatly appreciated! Good luck on your project!
    – webtesa
    Aug 28, 2012 at 18:22
  • The value of the custom field will not save in the database? did you have this same problem?
    – webtesa
    Aug 28, 2012 at 22:32
  • The custom field values appear to be working fine for me, the values appear in the custom fields area on the post edit screen
    – Jo_pinkish
    Aug 28, 2012 at 22:36
  • Also, yes I just noticed today that the validation isn't working at all, no idea why as I used code other people had shared. I will look in to this and also I don't know if the data being passed through to the database is being sanitized and is therefore safe. This is another thing I am going to research. It's been a big learning process!
    – Jo_pinkish
    Aug 28, 2012 at 22:37
  • You're right, I had the wrong input names, it is showing up in the custom fields now. I will work on the validation and security as well. If I get anything I will post for you and hopefully you will do the same?
    – webtesa
    Aug 28, 2012 at 23:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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