0
votes

I'm having trouble defining a function in advance custom fields. Basically i need a field populated by a title(text field), a wysiwyg editor and two file upload fields on the bottom of a few product pages. But i only want to show the field+title if one of the fields is populated.

product info fields are:

product_info_title - Text field

product_info_content - wysiwyg editor

product_info_file_1 - File

product_info_file_2 - File

here is my current acf code in my custom page template:

<div class="post-content">
    <?php the_content(); ?>
        <?php 
        if( function_exists('get_field')) {
        if(get_field('product_info_content')) {
        echo '<div class="info-box">';
        echo '<h1>' . get_field('product_info_title') . '</h1>';
        the_field('product_info_content');
        echo '</div>';
        }
        }
        ?>

What i can't get to function properly is to check if ANY of the three fields i have besides the title field is populated and if so display it along with the title field.

1
Please correct me if i wrong. You are currently want to check if one of three field ( product_info_content, product_info_file_1, product_info_file_2 ) populated and you will show product_info_title field. If what I think was right. Maybe you can use javascript to archive this problem. - christian Nguyen

1 Answers

0
votes

So you want to show something if one field OR another are populated, then you need to use OR in your condition:

if( field1 OR field2 OR field3 ) {
   // show something
}

Applied to your code the condition would be something like:

if ( get_field('product_info_content') OR get_field('product_info_file_1')  OR get_field('product_info_file_2') ) {
    // echo the <div>
}