Support

Account

Home Forums ACF PRO ACF PRO: Label + Value pairs of Field groups in front end – almost there, but… Reply To: ACF PRO: Label + Value pairs of Field groups in front end – almost there, but…

  • Hi @james,

    thank you! you definitely put me on the right track here.

    I have achieved the desired result, and also managed to unecho unwanted groups here.

    I’ll mark this as solved, post my code below in case it might help others, and kindly ask you to review my code in case you think there could be smarter ways to get to the same point:

    <?php
    
    $groups = acf_get_field_groups(array('post_id' => get_the_ID()));
    foreach( $groups as $group_key => $group ) {
        $fields = acf_get_fields($group);
    
    // below starts condition to unecho unwanted field groups 
    	 if($group['title'] !== 'pagelicks'){
    	    echo '<h2>'.$group['title'].'</h2>';
    		echo '<dl class="techspecs">';
    	    if($fields ) {
    	        foreach( $fields as $field_name => $field ){
    		        $value = get_field($field['name']);
    	        	if( $value && $field['label'] !=='Bollicine' && $field['label'] !=='tipologia prodotto' ) {
    		            echo '<dt>' . $field['label'] . '</dt>';
    		            echo '<dd>' . $value. '</dd>';
    	            }
    	        }
    	    echo '<dl>';
    	    }
    	// below ends condition to unecho unwanted field groups
    	}
    }
    ?>

    Your help was priceless, thanks again!

    Alessio