Support

Account

Home Forums General Issues acf select field to custom function

Helping

acf select field to custom function

  • Hi I’m trying to create a switch function in a Child Theme functions.php to a value returned by acf select in a custom post template, like this:

    custom_post_template.php

    <h6>
    
        <?php conserva(the_field('especial')); ?>
    
    </h6>

    functions.php

    <?php
    
    function conserva($conserva){
     
     switch($conserva) {
    	 
    	 case 'EX':
    	 $conserva = 'item 1';
    	 break;
    	 
    	 case 'EW':
    	 $conserva = 'item 2';
    	 break;
    	 
    	 case 'CR':
    	 $conserva = 'item 3';
    	 break;
    	 
    	 case 'EN':
    	 $conserva = 'item 4';
    	 break;
    	 
    	 case 'VU':
    	 $conserva = 'item 5';
    	 break;
    	 
    	 case 'NT':
    	 $conserva = 'item 6';
    	 break;
    	 
    	 case 'LC':
    	 $conserva = 'item 7';
    	 break;
    	 
    	 case 'DD':
    	 $conserva = 'item 8';
    	 break;
    	 
    	 case 'NE':
    	 $conserva = 'item 9';
    	 break;
    
    	 return $conserva;	 
     }
     
     }
    
    ?>

    Didn’t Work.

    Any clue.

    Ty in advance

  • use get_field() instead of the_field(). the_field() echos the value which you don’t want to do.

    
    <h6>
    
        <?php conserva(get_field('especial')); ?>
    
    </h6>
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘acf select field to custom function’ is closed to new replies.