1

Can someone know the answer about it I have field set and i want when they are empty show some text now there is showing nothing

<div class="place-bottom-row">
    <?php if(get_field('pojedynczy_wpis')): 
    $i = 0; 
    $today = date('d-m-Y'); //This has to match the format of your date field
    ?>
        <?php while(has_sub_field('pojedynczy_wpis')): ?>
            <?php if(strtotime($today) <= strtotime(get_sub_field('danie_na_dzien'))){ ?>
                <?php if($i < 2){ ?>
                    <?php $i++; ?>
                    <?php the_sub_field('danie_rodzaj'); ?>
                    <?php the_sub_field('danie_opis'); ?>
                    <?php the_sub_field('danie_cena'); ?>
                <?php } ?>
            <?php } ?>
        <?php endwhile; ?>
    <?php else:  ?>

    <?php endif; ?>
</div><!-- place bottom row end -->
2
  • 1
    You do not have to wrap every individual line with <?php ?>. Instead, wrap whole sections of php, together. Commented Apr 29, 2015 at 13:29
  • I know but this is not answer for my question Commented Apr 30, 2015 at 14:07

1 Answer 1

1

Rather than using the_sub_field() (which echoes the return value), you should use get_sub_field():

<?php echo get_sub_field('danie_rodzaj') ? get_sub_field('danie_rodzaj') : 'Custom Text instead'; ?>

This will allow you to test if there's a value, before echoing it.

Sign up to request clarification or add additional context in comments.

3 Comments

This solution does work. If it doesn't, you should be receiving an error, or at least some kind of content. Are you seeing the custom text?
No, there is nothing showing not error or not even text just blank space
It's not possible to show nothing, unless your sub field has no data associated with it. That snippet will always output something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.