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?

closed as off-topic by Mark Kaplun, TheDeadMedic, Howdy_McGee, cybmeta, s_ha_dum Dec 25 '15 at 18:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 Dec 25 '15 at 18:09
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 } ?>
  • What are you doing exactly ? Just remove a comment line ? – Daniel Noaein Dec 21 '15 at 7:43

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