Thanks very much. Could you possibly give me an idea on the implantation. IE. which but of code goes where. Many Thanks
–
Robin I KnightFeb 4 '11 at 21:13

2

Nicely done. The second code block replaces yours, the function values is the custom field key/value pair. Put the function either at the top of the script, or in a separate .php file included at the top of the script.
–
aendrewFeb 4 '11 at 21:37

I couldn't have put it any better than aendrew honestly. +1
–
ZackFeb 4 '11 at 21:44

As a note, I do use OOP so that's the reason for the public modifier in front of "function". If you're including the function itself without putting it into a class, you don't need to add public
–
ZackFeb 5 '11 at 3:13

The reason is because of how WP stores the two data types. Posts are stored in one big monolithic table with a dozen different columns (wp_posts); custom fields are stored in a simpler, 4-column table (wp_postmeta) comprised mainly of a meta key and value, associated with a post.

Consequently, you can't really store custom fields until you have the post ID.

In that case the only way out I can see is to use a session, would that be correct.
–
Robin I KnightFeb 4 '11 at 20:42

Nah; I'm guessing your plugin is trying to insert custom fields at the same time a post is saved, right? I think what you need to do is hook into WP after the post is saved, grab the post's new ID number, then supply that to add_post_meta(); to create the CFs. I'll update my answer in a second with some code.
–
aendrewFeb 4 '11 at 20:48

Thanks for the help. By the way its not a plugin. I wrote it so we can customise it as much as needed. (but don't take that to mean I'm any good with php, just trial and error)
–
Robin I KnightFeb 4 '11 at 20:52

It's a theme, then? Only real difference is you'd put that in functions.php, in that case.
–
aendrewFeb 4 '11 at 21:00