0

I am trying to call a field and it's heading on a post type. I want to call headings only if there is content in the field. I'm really new to PHP and am unsure how it all works. I have added the following script in content-single.php

 <?php $field = get_field('introduction'); 
    if(!empty && is_array){
        ?>
         <div class="sc-project-type">
            <h4>Introduction:</h4>
            <?php //$terms = get_the_terms($post->ID, 'project_type');
                echo '$field'; ?>
         </div>
        <?php } ?>

This brakes produces nothing. If I just , it works, but I want to add lots of fields that won't always be visible. Any ideas?

1
  • Your code is very broken. empty() and is_array() are both functions but you've left off the parens and the arguments. If you have debugging enabled you'd probably see warnings about undefined constants. At any rate, it won't work as you need it to.
    – s_ha_dum
    Commented Dec 25, 2015 at 18:09

1 Answer 1

1

OK, after playing for a while, I solved my issue with the following code:

        <?php $field = get_field('introduction');
    if(!empty ($field)){
        ?>
         <div class="sc-project-type">
            <h4>Introduction:</h4>
            <?php echo ($field); ?>
         </div>
        <?php } ?>
1
  • What are you doing exactly ? Just remove a comment line ?
    – Danial
    Commented Dec 21, 2015 at 7:43

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