I am working on a project where I am creating a plugin that works on top of ACF 5. I have made it pretty far but right now I am stuck on this issue:
I have a flexible content field setup that has multiple sub layouts. I need to add conditional logic to each of these layouts based on there names. Right now I am doing it by getting their field ID:
$field_id = $field['ID'];
*$field being my main array.
Then doing a simple php switch statement just setting a variable I can then check for when doing conditional logic:
$layout = '';
switch ($field_id) {
case "19":
$layout = "html";
break;
case "28":
$layout = "grid";
break;
}
Then I just check to see what $layout is set to and go from there. While this does work I do not like the fact that I have to update the IDs every time I move development environments or re-create a layout.
Is there a way I can do this dynamically?
Thanks!
The ‘key’ value of each layout should remain the same. These are created in a similar way to field keys. The keys are unique, and like I said, should not change during export and import. If you recreate the layout from scratch though, I think you’ll always need to change your code to match the field.
I have updated it to use keys and that seems to work perfectly! Thanks a bunch!