K
K
Koxae2018-02-05 18:46:05
WordPress
Koxae, 2018-02-05 18:46:05

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;

Help me please!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
avakulenko, 2018-02-07
@css0101

Thanks for the provided code. The problem is that once you've got the data for the entire complexfield, 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');
      }
    }	
  }
}

Hope it helped!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question