[wp-hackers] Allow users to upload their own images - hook to use?

J.D. Grimes jdg at codesymphony.co
Thu Sep 12 13:35:24 UTC 2013


On Sep 11, 2013, at 7:01 PM, BenderisGreat <greglancaster71 at gmail.com> wrote:

> Wait this could be the answer to everything I need done.  You said I can
> attach it to a post, so each users uploads would be associated to their
> specific post.  If I am doing that is it also possible to associate the data
> I am saving with my form to that post as well?  How would that be done?
> custom fields or something?

Yes, you can do that using post metadata AKA custom fields. 

http://codex.wordpress.org/Function_Reference/add_post_meta

> Last followup question - how
> would I take the post->id from the image upload and drop it into my table. 
> (so each entry is properly matched up with the correct image)


The post ID is returned by wp_insert_attachment():

http://codex.wordpress.org/Function_Reference/wp_insert_attachment#Return_Values

So you would just need to use $wpdb->insert() with that post ID (if you are going to use the custom table instead of post meta).

http://codex.wordpress.org/Class_Reference/wpdb#INSERT_rows



More information about the wp-hackers mailing list