I'm having an array of different posts and products:
array (size=2)
0 =>
array (size=2)
'acf_fc_layout' => string 'post'
'linked_post' => int 6802
1 =>
array (size=2)
'acf_fc_layout' => string 'product'
'linked_product' => int 5140
My problem now is that I want the array of post/and product to contain the entire post/product object instead of just the ID. Im also using twig which makes it hard to query the object inside the view. So what I've tried is to do it from the backend side:
// Getting the array of Posts and Products
$gallerix = get_field('gallerix_layout', 'options');
// Trying to overwrite the value in the loop
foreach ($gallerix as $gallerix_item) {
if ( $gallerix_item->acf_fc_layout == 'product' ) {
$gallerix_item->linked_product = wc_get_product( $gallerix_item->linked_product );
} elseif ( $gallerix_item->acf_fc_layout == 'post' ) {
$gallerix_item->linked_post = get_post( $gallerix_item->linked_post );
}
}
// Pass the array to Timber/Twig
$context['gallerix'] = $gallerix;
// Render twig template
Timber::render( 'views/template.twig', $context );
Hope somebody understands my problem. Any support is very appreciated.