I have this simple code, but can’t get the_content and the ACF-code to work together.
If I include the_content() it blocks out the ACF-code, but if I remove the_content() the ACF-code works fine. I suspect there’s a very simple solution to this.
I’ve simplified and removed unnecessary elements from the code below:
<?php while ( have_posts() ) : the_post(); ?> <?php the_content(); ?> <?php if( have_rows('boxes') ): ?> <p>This is only shown when the_content() is removed.</p> <?php else : // no rows found endif; ?> <?php endwhile; ?>
Just for information, this is a bug in WP and autop. You can view the ticket here and it does not look like it will be fixed any time soon. The work around is to start your multiline comment with
<!-- and end it with
<?php $acf = false; while ( have_posts() ) : the_post(); if( have_rows('boxes') ) $acf = true; the_content(); if( $acf == true ): echo '<p>This is only shown when the_content() is removed.</p>'; else : // no rows found endif; endwhile; ?>
This is not a perfect solution but a quick workaround.
Well, I found out what it was. Actually I think this might be caused by a bug in WordPress (or perhaps one of the add-ons I’m using).
In the content editor I had blocked out some of the code with “”. For some reasonthe closing markup “–>” didn’t get registered, so in the code anything after
the_content(); got blocked out.