Support

Account

Home Forums ACF PRO Append and Prepend values

Solved

Append and Prepend values

  • Hi. How do i retrieve/display the Append and Prepend values inside the page http://prntscr.com/gl5o1v .
    i added this code:

    
    <?php
    if(get_field('lon_pay') ):
    $field_name = "lon_pay";
    $field = get_field_object($field_name);
    echo '<li>';
    echo '<h3>'. $field['label'] . '</h3>';
    echo '<div class="field-text">'. $field['value'] . '</div>';
    echo '</li>';
    endif; 
    ?>

    but only shows the field value inside. I am using it with the range slider.

  • You would need to specifically get these values and show them $field['prepend'] & $field['append']

  • Was it that easy?? 🙂 damn…
    One other issue i hit, i made a checkbox list containing taxonomy.
    I cant show the values. The result i get is a text “Array” instead of the actual value/label selected.
    I tried all possible codes i could find in this forum, but no solution.

  • easy if you already know all of the field values. print_r($field)

    A taxonomy field returns an array of term objects. You need to loop through the array. There are code examples here https://www.advancedcustomfields.com/resources/taxonomy/

  • i cant make it work 🙁

    here is what I’m using:

    <?php								if(get_field('job_field_area') ):
    $field_name = "job_field_area";
    	$field = get_field_object($field_name);
    	echo '<li class="list-item">';
    	echo '<div class="list-content">';
    	echo '<h3>'. $field['label'] . '</h3>';
    	echo '<div class="field-text">';
    	echo implode(', ', $field['value']);
    	foreach ($field['value'] as $value);
    	echo '</div>';
    	echo '</div>';
    	echo '</li>';
    	endif; 
    ?>

    and I’m getting just the label… eg.Job “Field Area” but no values for it.

  • You can’t just implode the array, it consists of an array of term objects and not just the name of the terms. You must loop through it and pluck out the term names, or you can use a WP function that does this

    
    $field_name = "job_field_area";
    $field = get_field_object($field_name);
    if ($field) {
      ?>
        <li class="list-item">
          <div lass="list-content">
            <h3><?php echo $field['label']; ?></h3>
            echo implode(', ', wp_list_pluck($field['value'], 'name'));
          </div>
        </li>
      <?php 
    }
    
  • ok…you missed some php tags in there but i added them. Though…the result is the same as in the code i used before this 🙁

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

The topic ‘Append and Prepend values’ is closed to new replies.