This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Relational custom field

#39263
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Relational and object storage fields will not work this way, as those have to be queried exactly by structure in a loop or a single post environment.

The only way to print this data is to use custom code, to fetch all the needed information and add it to the content field, fetched on demand exactly as needed. I am not sure about your exact field setup, but via using the asp_results hook, this could be a potential way of getting the field values:

add_filter('asp_results', 'asp_fetch_acf_relationship', 10, 1);
function asp_fetch_acf_relationship($results) {
    $relationship_field_name = 'informazioni_generali';
    $field_name = 'sedi';

    // ----------------------------------------------------------------
    if ( function_exists('get_field') ) {
		foreach ( $results as &$r ) {
		   $items = get_field($relationship_field_name, $r->id);
		   if ( is_array($items) ) {
			   foreach ($items as $item) {
				  if ( isset($item->ID) ) {
					  $custom_field = get_field( $field_name, $item->ID );
					  $r->content .= $custom_field;
				  }
			   }
		   }
		}
    }

    return $results;
}

But once again this is just a possible sample, it highly depends on the field structure.