Home Forums Add-ons Repeater Field Grab Value From Options Page Rep. Field


Grab Value From Options Page Rep. Field

  • Hello!

    So I have been having a hard time finding a solution to this. Any help would be greatly appreciated.

    I have an options page with a repeater field. In this repeater the operator can fill in a NAME and VALUE field.

    In my functions.php I grab another custom field for a product, also called NAME. I need to find if the value NAME exists in my repeater field, then grab the VALUE that corresponds with it. I’m mostly a front end dev and this issue is pretty new to me, so I am lost as to how I am going to grab the VALUE field from the corresponding NAME field in this repeater.

    Is this something that is possible? If so, could someone point me in the right direction?

    Again, thank you for any help provided!

  • Hi @sainc

    To get the value from an options page, you need to set ‘option’ as the second parameter of get_field() or have_rows() functions. This page should give you more idea about it:

    you can get the repeater value using get_field() and then print it like this:

    print_r(get_field('repeater_field_name', 'option'));

    This will help you understand what is inside the repeater field. After that, you can iterate the array to check the name.

    I hope this helps.

  • Thank you James for getting back to me!

    Calling the value of the options page repeater is not a problem for me. Where I am stuck is when I need to “search” that array for the keyword.

    To type out logically what I am stuck at would be something like “If <keyword> is in <array row 1>, grab corresponding value of <array row 2>. This is probably more relevant to just general PHP coding than ACF, but as a front end dev, this isn’t something I’m all to familiar with. And I cant seem to find any resources online for this type of issue.

  • Hi @sainc

    I think you can use something like this:

    $repeater = get_field('repeater_field_name', 'option');
    foreach ($repeater as $content){
        if ($content['name'] == "name_1"){
            echo $content['value'];
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.