• Resolved Begin

    (@bentalgad)


    In the wiki you shoe how to get group fields with foreach loop. is there a shorter way if i want to get just one field from a group?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Begin

    (@bentalgad)

    Got it:
    echo get_post_meta( get_the_ID(), 'wiki_test_repeat_group', true )[0][title];
    Will work.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    That would work. Another idea, in case you know you can’t rely on the desired data being in the same index each time would be to loop through them all and conditionally echo or pluck into its own variable that you could echo afterwards.

    Thread Starter Begin

    (@bentalgad)

    Yes but that would be a really long code to echo just one field…

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    No doubt, but *potentially* a necessary route if it’s not guaranteed to always be in index 0.

    Nitpicky, but looking over the code snippet provided, may be best to quote that “title”. Otherwise it may be interpreted as an undefined constant.

    echo get_post_meta( get_the_ID(), 'wiki_test_repeat_group', true )[0]['title'];
    
    Thread Starter Begin

    (@bentalgad)

    Oh, yes i actually did in my real code. thanks.

    BTW – why wouldn’t be in the index 0?

    It will happen only if i use repeatable fields right? if i don’t i have nothing to worry about right?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Depends on the overall structure and intent you have. Especially with a repeatable group where the order may be changed in the admin and you’re needing to output specific content in specific spots. Long story short from my end, best to know variations of how to access the data being saved. 😀

    Thread Starter Begin

    (@bentalgad)

    Ok, thanks!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Get just one group field’ is closed to new replies.