Support

Account

Home Forums Backend Issues (wp-admin) Getting the values from a custom field

Solved

Getting the values from a custom field

    • Gonzalo

    • March 15, 2019 at 10:50 pm

    Hi,
    I am working with a theme that has embedded taxonomies with custom fields.

    Custom Field

    Within this custom field there are many values created. My question is, how do I get all the values available, and also, in particular, how do I get the ID for a specific field save that has a specific value?

    Thanks

  • Are you talking about getting the fields that are on the “Related Posts” that are selected? This is covered in the documentation for the relationship field. https://www.advancedcustomfields.com/resources/relationship/

    • Gonzalo

    • March 16, 2019 at 8:14 pm

    Thanks for the quick response.
    To clarify more my doubt, here I attach a dump of my postmeta DB:

    DB

    When I try to update the POST field=field_5628165af3668 with:

    update_field('field_5628165af3668','777',$postid);

    It doesn’t add the values on the DB as it does when I select the option in the backend.
    What I am doing wrong?

    Thanks

  • A relationship field holds an array of post IDs. In order to add a value you need to first get the existing value and add to it. Example:

    
    $value = get_field('field_5628165af3668', $post_id);
    $value[] = '777';
    update_field('field_5628165af3668', $value, $post_id);
    
    • Gonzalo

    • March 17, 2019 at 2:32 am

    Thanks John, that did the trick!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.