Support

Account

Home Forums Front-end Issues Multiple checkbox (array in front-end)

Solving

Multiple checkbox (array in front-end)

  • Hello, I have a problem: I have a field type “checkbox” with three options on the administrator’s side, I need to display the selected values on the user’s side (on the record page). But now everything is displayed like this: array checkbox

    Code from page

    <?php 						$field_name = "service_for";
    						$field = get_field_object($field_name);
    						
    						echo '<div class="col-xs-4 col-lg-3"><strong>' . $field['label'] . ':' . '</div></strong>';
    						echo '<div class="col-xs-8 col-lg-9">' . $field['value'] . '</div>';
    						
    					?>

    Please, how to display all selected values in a row

  • Take a look at the documentation: https://www.advancedcustomfields.com/resources/checkbox/

    This example works, if you selected “Both (Array)” in “Return Format” option

    
    <?php
    $field_name = "service_for";
    $fields = get_field($field_name);
    
    if($fields){
    foreach ($fields as $field){
    	echo '<div class="col-xs-4 col-lg-3"><strong>' . $field['label'] . ':' . '</strong></div>';
    	echo '<div class="col-xs-8 col-lg-9">' . $field['value'] . '</div>';
    }
    }
    ?>
    
  • Hi, When I use this code, everything is displayed like this:

    I need to be displayed as: “Service for: Man Couples”

    Can this be realized?

  • <?php
    $field_name = "service_for";
    $fields = get_field($field_name);
    
    if($fields){
        echo '<div class="col-xs-4 col-lg-3"><strong>Service for:</strong></div>';
        echo '<div class="col-xs-8 col-lg-9">';
        foreach ($fields as $field){
    	    echo $field['value'] . ' ';
        }
        echo '</div>';
    }
    ?>
  • it works great, but the site has two languages, and when you switch to another (Turkish) is displayed “Service for”

  • This was not your question in previous comments.
    Read the Documentation about Multilingual Custom Fields.

  • Hi,

    I am using this code. But I need to show more than one field, how do I do this? The next field I’ve added is showing as empty in the front-end. Here is the code I have:

    
    function woo_new_product_tab_content()  {
    
    $field_name = "gate_usage";
    $fields = get_field($field_name);
    
    if($fields){
         echo '<li>';
        foreach ($fields as $field){
    	    echo $field['value'] . ' ';
        }
        echo '</li>';
    }
    	$field_name = "motor_supply";
    $fields = get_field($field_name);
    
    if($fields){
       
        echo '<li>';
        foreach ($fields as $field){
    	    echo $field['value'] . ' ';
        }
        echo '</li>';
    }
     }
    

    Why is it not working please?

    Thanks.

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

The topic ‘Multiple checkbox (array in front-end)’ is closed to new replies.