Forums

Ultimate Post Type Manager
Function to add/update custom field (6 posts)

  1. Nir
    Member
    Posted 11 months ago #

    Hello There,

    First, great plugin, thanks for that.

    Second, I tried adding (or updating) custom fields using the wordpress function add_post_meta() (or update). For some reason this didn't work with the plugin and the values did not show right on the post. I noticed that the plugin uses a json format for the custom fields, is the another function I should use, instead of the regular wordpress one ?

    Thanks in advance,

    Nir.

  2. XYDAC
    Member
    Posted 11 months ago #

    Hey Nir,
    As you have seen i use a different format to store data, The format is as below:
    meta_name : {field_name}
    meta value : array({field_type} => {field_value})
    If you wanna coin a function yourself then you can, Else i'll write it up sometimes later..:)

    Regards,
    -Xydac

  3. Nir
    Member
    Posted 11 months ago #

    can You show and example of using the add_post_meta/update_post_meta with your format ?

    Thanks.

  4. XYDAC
    Member
    Posted 11 months ago #

    update_post_meta(post->ID,$field_name,array('text'=>$field_value));

    this should work, else i would check it out later when i return. I am traveling right now.

    Regards,
    -Xydac

  5. Nir
    Member
    Posted 11 months ago #

    Thanks a lot,

    Two more questions:

    1. what if the key is not 'text' ? could that be ?

    2. how do You get the value - please show an example of get_post_meta().

    Again, thanks in advance,

    Nir

  6. XYDAC
    Member
    Posted 11 months ago #

    Hey,

    1. yes it's possible that key is not text, it's different for each field type. look for $name='' in fieldtype/class-fieldtype.php files.

    2.get_post_meta() should work as follow :

    global $post;
    $val = get_post_meta($post->ID, {field_name}, true);
    echo $val[{fieldtype}];

    for example if field type = text, fieldname = username then

    global $post;
    $val = get_post_meta($post->ID, 'username', true);
    echo $val['text'];

    Hope this solves your problem,
    BTW sorry for delay in response.

    Regards,
    -Xydac

Reply

You must log in to post.

About this Plugin

About this Topic