Okay, so I have worked myself to this functons which seem to do the trick:
function abGetAllFields($pro_num){
$tmpArr = get_field_objects($pro_num);
$fillArray = array();
foreach( $tmpArr as $tmpFieldObject ) {
$fillArray = abGetAllFieldsCycle($fillArray, $tmpFieldObject["name"], $tmpFieldObject["value"]);
}
return $fillArray;
}
function abGetAllFieldsCycle($fillArray, $name, $value) {
if (is_array($value)) {
foreach( $value as $key => $value ) {
$fillArray = abGetAllFieldsCycle($fillArray, $key, $value);
}
} else {
array_push($fillArray, [$name, $value]);
}
return $fillArray;
}
$myFieldArray = abGetAllFields($pageId);
well, no … or kinda. I did try “get_field_objects” (first thing I tried) but trying out the gathered field-objects (“name” and “value”), those objects with repeaterfields only returns arrays for “value”, and I dont know how to further break this value-arrays apart, since those could contain arrays themself and so on.
I just need every field of a page gathered, be it normal or subfield, and put into one array. So … pretty much the function I described a bit further up … but filled and working XD. Yet I’m starting to think getting this to work will not be as easy as I had hoped :-S ^^
first up, thanks for the response 🙂 … I’ll try around with it. As for “what im really looking for”, im trying to create an array that holds all data from every field within a page, be it normal or repeaterfields (or repeaterfields within repeaterfields etc.). So in the end the mentioned array should be full of either fieldobjects, that I could extract data from (“name”, “value”, “type” etc.), or little arrays that hold this data, like [“thefieldname”, “thefieldvalue”, “thefieldtype”].
So Im kinda trying to fill a function like this:
function getAllFields($pageID) {
$everyFieldData = array();
…
…
(push fields or [name,value,type] of every field/subfield in $everyFieldData)
…
…
return ($everyFieldData);
}
How would I possibly approach or fill a function like that?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.