Support

Account

Home Forums General Issues Multiple True/False Field

Solved

Multiple True/False Field

  • Hi I have two true/false fields on a product post type. If either one of them is ticked I want them to add a class to some tabs code, but if they are both ticked I want them to add a different class or if neither are tagged, a different class again. I worked out some code which works for when either one of them is tagged. See below

    <?php 
    if ( get_field( 'other_information_check' ) ): 
    echo "3-tabs";
    elseif ( get_field( 'products_specs_check' ) ): 
    echo "3-tabs";
    elseif ( get_field( 'other_information_check' ) || get_field( 'products_specs_check' ) ) :
    echo "4-tabs";
    else: // field_name returned false 
    echo "2-tabs";
    endif; 
    ?>
    

    but if both are ticked, it won’t add the 4-tabs class, instead it adds the 3-tabs class as if only one of them is tagged. I am no php expert so I know its my statement, but can this even be done, if so, can some one point me in the right direction please

  • 
    <?php 
    	if ( get_field( 'other_information_check' ) && get_field( 'products_specs_check' )): // both checked
    		echo "4-tabs";
    	elseif ( get_field( 'products_specs_check' ) || get_field( 'other_information_check' ) ): // one or the other is checked, but not both
    		echo "3-tabs";
    	else: // no fields checked
    		echo "2-tabs";
    	endif; 
    ?>
    
  • Thank you so much good Sir, got me out of a hole that one, knew I was doing something wrong

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Multiple True/False Field’ is closed to new replies.