Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom Fields Don't Insert After Publishing WordPress

  • REFUNDED

This is how it looks when I try to add a new post:

[[LINK href="http://dl.dropbox.com/u/118004/Screen%20shot%202010-05-12%20at%2010.45.35%20AM.png"]]Screenshot[[/LINK]]

This is the code I use in functions.php:

add_post_meta($post_id, 'Post Thumbnail', $post_thumb, true) or update_post_meta($post_id, 'Post Thumbnail', $post_thumb);
add_post_meta($post_id, 'Project URL', $url, true) or update_post_meta($post_id, 'Project URL', $url);
add_post_meta($post_id, 'Project Thumbnail', $thumb, true) or update_post_meta($post_id, 'Project Thumbnail', $thumb);


I complete the fields, hit update then publish and when the page is refreshed, the fields disappear. I have to go down to the dropdown select them and add them again to make it work. Any ideas?

Also, is there any other way to insert post meta keys to the custom field dropdown when I install the theme without showing the custom fields when adding a new post? This would be a better solution considering that users don't need to use all 3 fields in one post.

Answers (6)

2010-05-12

Oleg Butuzov answers:

You should use this structure, more effect...


$valiable = 'demo';
/**
*** Variable also can be a array or object
**/

$key = 'somekey';
/**
*** If key will have underscore (_) before, it will he hidden from edittion via custom meta fields
** _hideme as sample
** done use space for post meta_key
**/


if (!update_post_meta($post_id, $key, $valiable)){
add_post_meta($post_id, $key, $valiable);
}



you also can fix you metakeys to

post_thumbnail
project_thumbnail
project_url


Oleg Butuzov comments:

is it a answer on your question?


Oleg Butuzov comments:

BTW, istead using of post_thumbnail you can use the native feature of the 2.9 version called Post Thumbnail =)
http://wpengineer.com/new-feature-in-wordpress-2-9-the_post_image/


norbiu comments:

Nope, the problem is still there. I used a fresh WP install.

This is how it looks [[LINK href="http://dl.getdropbox.com/u/118004/Screen%20shot%202010-05-13%20at%2012.57.34%20AM.png"]]before[[/LINK]] I click 'publish'. And this is [[LINK href="http://dl.getdropbox.com/u/118004/Screen%20shot%202010-05-13%20at%2012.56.33%20AM.png"]]after[[/LINK]] the page is refreshed.


Oleg Butuzov comments:

hm... the data alsready in your db. (that's why you see the meta fields in select)

have you disable revisions in wp-config.php?

define('WP_POST_REVISIONS', false);


norbiu comments:

The data that I enter in the custom fields in the before screenshot aren't being inserted into the database.

I have to go back after I hit publish to select each on again for it to work.

2010-05-12

Utkarsh Kukreti answers:

What exactly are you trying to do?


norbiu comments:

I'm trying to add custom fields for the user (project thumbnail and project url for the project section and post thumbnail for the blog section)

2010-05-12

Edouard Duplessis answers:

do you know the plugin "custom field template" ....

Very nice and it's have a upload file field... try it it's gonna save you lot of time


norbiu comments:

I'm trying to avoid plugins as much as possible in this theme :)

2010-05-13

Merne Asplund answers:

I think it is costly to avoid good plugins, because you will basically be re-inventing the wheel and wasting time to achieve the same thing. Magic fields is another good custom fields plugin.

You should really consider using one as reference if you plan on writing your own.

2010-05-14

Ali Hussain answers:

<blockquote>I'm trying to add custom fields for the user (project thumbnail and project url for the project section and post thumbnail for the blog section)</blockquote>


Will 3 Meta Boxes be okay for you. one for each

2010-05-15

itshameem answers:

this link might help you
http://www.boosten.org/using-custom-fields-in-wordpress-posts/