1

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; ?>
2
  • If you use <?php the_content(); ?> below of ACF code, then do you see the text "This is only shown when the_content() is removed"? Nov 5, 2014 at 10:57
  • Tried that now. Yes, when putting it below the ACF-code I can see both the test-paragraph "This is only shown (…)" and the content. Apparently it doesn't work when the content is put before. Nov 5, 2014 at 11:02

3 Answers 3

3

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 <!-- -->

0

Try this:

<?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.

1
  • It doesn't work – nothing gets displayed. Also, if I put a test-paragraph before the if( have_rows('boxes') ) $acf = true; it gets displayed, but if I place it after it doesn't. It seems like anything after the_content(); and/or your if-line get ignored. Nov 5, 2014 at 11:19
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.