Home › Forums › ACF PRO › Get all Texts form Flexible Contents and nested Repeater › Reply To: Get all Texts form Flexible Contents and nested Repeater
Perfect, thanx!
this is mit current “final” function:
// function to get the conntent of all custom fileds fron array to one string ---------------------------------------------------------------------------------------
function get_fields_content($include_fields, $fields) {
// loop the fields and add all content to one string
if( $fields ) {
foreach( $fields as $field_name => $field ):
$fieldname = $field['name']; // get the cutom field name for the filter
$fieldvalue = $field['value']; // get the content of the field
// filter by cutomfield from array and if value has content
if ((in_array($fieldname, $include_fields) && ($fieldvalue))) {
// add too $content a spache and a line break behind each field and add the html-stripped content from the next field
if ( !is_array($fieldvalue)) {
$content .= strip_tags($fieldvalue) . ' ';
} else {
// for the subfields if acf flexible content layouts ----------------------------
// https://support.advancedcustomfields.com/forums/topic/get-all-texts-form-flexible-contents-and-nested-repeater/
foreach( $fieldvalue as $row ){
foreach( $row as $k => $column){
if( $k !== 'acf_fc_layout' && !is_array($column) && !is_object($column) ){
// get the current field name
$current_field_name = str_replace($row['acf_fc_layout'].'_', '', $k);
// check if in array
if( in_array($current_field_name, $include_fields) ){
$content .= strip_tags($column) . ' ';
}
}
}
}
// end subfields ----------------------
}
}
endforeach;
}
return $content;
}
// -------------------------------------------------------------------------
and to get the fields and call the function:
$fields = get_field_objects();
$include_fields_content = array('acf_field_1' , 'acf_field_2' , 'acf_field_3);
$content = get_fields_content($include_fields_content, $fields);
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.