I'm sure I'm doing something basic wrong here. Trying to insert a quote block after the second paragraph of a WordPress post if there is content in the field. If not, I want to add the content without the block. The code works outside of the if else statement but not when within it. I've used the Advanced Custom Fields plugin to create the field. Can anyone help? Here's my code:
<?php
$show_after_p = 2;
$content = apply_filters('the_content', $post->post_content);
$contentblock = the_field(post_quote_block);
if (!empty($contentblock)) {
if(substr_count($content, '<p>') > $show_after_p)
{
$contents = explode("</p>", $content);
$p_count = 1;
foreach($contents as $content)
{
echo $content;
if($p_count == $show_after_p)
{
?>
<div class="blogQuoteBlock"><div class="blogQuoteBlockText"><?php the_field(post_quote_block) ?></div></div>
<?php
}
echo "</p>";
$p_count++;
}
}
}
else {
<?php the_content(); ?>
}
?>