Custom Post Fields / Entries Not Saving – Solved
If you are diving into WP 3.0, you have probably looked into Custom Posts. I see integrating this technology into future themes, as it is an amazing feature that is now part of the WordPress architecture.
To educate myself, I was checking out a tutorial here: http://www.vooshthemes.com/blog/wordpress-tip/create-a-professional-portfolio-using-wordpress-3-0-custom-post-types/
The trouble is that the tutorial had a bug in it that did not allow the Website URL data to be saved. While there were proposed fixes on the site, none of them worked for me unfortunately.
After Googling a bit, I stumbled upon a Tut at NetTuts+ : http://net.tutsplus.com/tutorials/wordpress/rock-solid-wordpress-3-0-themes-using-custom-post-types/. Similar to the Tut I was looking at, I noticed that there tutorial contained the same bug.
It was in the comment that Ro posted that pointed me to the solution.
Here is the code I altered for the Voosh Portfolio tutorial to help you save your custom post meta data.
Find this:
function update_website_url(){
global $post;
update_post_meta($post->ID, “website_url”, $_POST["website_url"]);
}
And replace with this:
function update_website_url(){
global $post;
if(isset($_POST["website_url"]))
update_post_meta($post->ID, "website_url", $_POST["website_url"]);
}
The key code is the bold line above. It is this if statement that does the magic. Of course this fix can be applied to any Custom Post script, and you would simply need to alter the variable name – in this case “website_url” – to your own.
My thanks to Ro for the solution and to the Tutorials from Voosh and NetTuts for helping me understand this great new feature in WP.
~ Aloha

