logo

$5
Custom Fields Don't Insert After Publishing

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

Screenshot

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.

norbiu | 05/12/10 at 2:58pm | Edit


(6) Possible Answers Submitted...

Note: norbiu felt their question was unanswered, so we granted them a refund.

Note: norbiu requested a refund. They offered no explanation.

  • avatar
    Last edited:
    05/12/10
    5:42pm
    Oleg Butuzov says:

    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

    Previous versions of this answer: 05/12/10 at 5:38pm | 05/12/10 at 5:40pm | 05/12/10 at 5:42pm

    • 05/12/10 5:43pm

      Oleg Butuzov says:

      is it a answer on your question?

    • 05/12/10 5:44pm

      Oleg Butuzov says:

      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/

    • 05/12/10 5:59pm

      norbiu says:

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

      This is how it looks before I click 'publish'. And this is after the page is refreshed.

    • 05/12/10 6:03pm

      Oleg Butuzov says:

      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);

    • 05/12/10 6:08pm

      norbiu says:

      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.

  • avatar
    Last edited:
    05/12/10
    5:40pm
    Utkarsh Kukreti says:

    What exactly are you trying to do?

    • 05/12/10 5:42pm

      norbiu says:

      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)

  • avatar
    Last edited:
    05/12/10
    6:25pm
    Edouard Duplessis says:

    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

    • 05/12/10 7:14pm

      norbiu says:

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

  • avatar
    Last edited:
    05/13/10
    10:29am
    Merne Asplund says:

    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.

  • avatar
    Last edited:
    05/14/10
    2:00am
    Ali Hussain says:

    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)



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

  • avatar
    Last edited:
    05/15/10
    3:58am
    itshameem says:

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

This question has expired.





Current status of this question: Refunded