If you're using ACF
in wordpress you can use get_field()
over the_field()
in order to store the output in your $output
variable:
$output .= get_field('200_200_1', 'option');
$output .= '<div class="databarcolor">' . $date4 . '</div>';
Question
I want to include:
<?php the_field('200_200_1', 'option'); ?>
before the opening div tag in the line below...
$output .= '<div class="datebarcolor">'.$dates4.'</div>';
I am not sure how to insert the php tag in these circumstances. This is a php file, btw.
Can someone point me in the right direction?
Solution
If you're using ACF
in wordpress you can use get_field()
over the_field()
in order to store the output in your $output
variable:
$output .= get_field('200_200_1', 'option');
$output .= '<div class="databarcolor">' . $date4 . '</div>';
OTHER TIPS
If you want to include the output of some other PHP code (for instance, if the_field
does some echo
calls) and you want to add that to the $output
variable, use ob_start
and ob_get_clean
, like so:
ob_start();
the_field('200_200_1', 'option');
$output .= ob_get_clean(); //This appends everything to $output that was echoed since the call to ob_start
$output .= '<div class="datebarcolor">'.$dates4.'</div>';
I think you either mean:
Include the file before executing this code:
include 'yourfile.php';
// ... some code ...
$output .= '<div class="datebarcolor">'.$dates4.'</div>';
or include the file and add it's output to $output
:
// start output buffer
ob_start();
include 'yourfile.php';
// get buffer contents and clean the buffer
$output .= ob_get_clean();
$output .= '<div class="datebarcolor">'.$dates4.'</div>';