Support

Account

Home Forums ACF PRO IF SubField of Repeater(A) matches SubField of Repeater(B), GET all SubFields(B)

Helping

IF SubField of Repeater(A) matches SubField of Repeater(B), GET all SubFields(B)

  • Really hope someone can help me with this.

    Heres the easiest way that I can explain what I am looking for…

    IF Sub Field of Repeater(A) on POST 1, matches Sub Field of Repeater(B) on POST 2, GET all Sub Fields from Repeater(B).

    Here is the structure I have…

    POST 1 – This is to act as a main list of all tools

    • Repeater Field (toolslist)
    • Text Sub Field 1 (tool_name)
    • Image Sub Field 2 (tool_image)
    • Textarea Sub Field 3 (tool_description)

    POST 2 – This is one post of many, that would list tools specific only to this post, but pull the data from the main list in POST 1.

    • Repeater Field (tools_materials)
    • Selection Sub Field 1 (tool_material) <– Contains a list of all tools that are in the main list (toolslist).
    • Text Sub Field 2 (tool_material_detail)

    So for example, once POST 1 (tools_list) is set up with a list of tools, I want to then be able to create POST 2, and simply select a tool using the selection sub field 1 (this list would be manually populated to match the names from tool_name in the main list). Then some how do a check in the while statement to see if tool_material from POST 2 matches up with tool_name from POST 1, and if so, pull all the data from that tool in POST 1 and display it on POST 2.

    I have tried numerous different methods with while statements and so on but I simply can’t get this to work from repeater to repeater. I managed to get it working if POST 2 only has a checkbox field (not a repeater), but I want to also incorporate the tool_material_detail to be able to append extra information on POST 2 if needed.

    So again, I want something like this (in baby language)…

    IF tool_material == tool_name,
    THEN GET tool_name, GET tool_material_detail (from matching tool_material), GET tool_image, GET tool_description.

    Apologies if this is communicated really badly but I find it complicated just thinking about it let alone explaining it. Would appreciate any help.

    Thanks in advance.

    ACF PRO v5.2.1
    WP v4.0.1

  • There isn’t going to be an easy way to do something like this. You are going to need to get all of the values from the repeaters of both posts and compare them.

    I would put them into arrays and then loop through both arrays.

    
    $match_found = false;
    foreach ($repeater_1 as $repeater_row_1) {
        foreach ($repeater_2 as $repeater_row_2) {
            // check if they are == here
            // if they are set match found to true
            $match_found = true;
            // if you want, when a match is found you ca break
            // out of this loop
            if ($match_found) {
                break;
            }
        }
        // you can do it again here
        if ($match_found) {
            break;
        }
    

    }

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

The topic ‘IF SubField of Repeater(A) matches SubField of Repeater(B), GET all SubFields(B)’ is closed to new replies.