Support

Account

Home Forums Add-ons Flexible Content Field Get field from post_object in Flexible Content Reply To: Get field from post_object in Flexible Content

  • Hi @Exelmans Graphics

    I think your issue lies within these lines of code:

    <?php if ( get_sub_field("chart") ) : ?>
    											<?php foreach ( get_sub_field("chart") as $p ) : ?>
    <?php echo get_permalink($p->ID); ?>
    												<?php if( get_field( 'highcharts_beschrijving_van_de_grafiek', $p->ID) ): ?>
    												<div class="description"><?php the_field('highcharts_beschrijving_van_de_grafiek', $p->ID) ?></div>
    												<?php endif; ?>

    The first line is OK (testing to see if your ‘chart’ custom field exists) but the line after is a foreach which makes no sense in this context as the post object in your chart field is a single value.

    If you want to get the data associated with another post using the post object field simply do something like the following:

    <?php if ( get_sub_field("chart") ) : 
    
    	$p = get_sub_field("chart");
    	// Variable now stores the post object for the post chosen by the user
    	
    	//You can now do stuff with that post e.g.
    	$my_other_post = get_field( 'highcharts_beschrijving_van_de_grafiek', $p->ID);
    	
    	//This is example only - I have no idea what this field is or does
    	if($my_other_post){
    		echo $my_other_post;
    	}
    
    endif;// End check for chart field
    ?>