Answer the question
In order to leave comments, you need to log in
Carbon Fields. How to display data from custom assotiation fields in complex?
Hello. It is not possible to display data from the custom fields of a record added using the association field, which is in the complex field.
if ( has_post_format('aside') ) : \\условие для формата постов
$places = carbon_get_post_meta( $post->ID, 'event_options' ); \\начало вывода из поля complex
if ( $places ) { foreach ( $places as $place ) {
echo $place['event_date'];
echo $place['event_time'];
$adress = carbon_get_post_meta( $post->ID, $place['event_adress'] ); \\начало вывода из поля association, моя самодеятельность. не работает
foreach ( $adress as $item ) {
echo carbon_get_post_meta($item['id'], 'venue_adress');
}
}
}
endif;
Answer the question
In order to leave comments, you need to log in
Thanks for the provided code. The problem is that once you've got the data for the entire complex
field, you don't need to use the carbon_get_post_meta()
. Below is an example of a working code:
if ( has_post_format('aside') ){
$places = carbon_get_post_meta( $post->ID, 'event_options' );
if ( $places ) {
foreach ( $places as $place ) {
$event_date = $place['event_date'];
$event_time = $place['event_time'];
$addresses = $place['event_adress'];
foreach ( $addresses as $address ) {
$venue_adress = carbon_get_post_meta($address['id'], 'venue_adress');
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question