0

I have a 'relationship' custom field that allows you to select multiple values and display them via

<?php $post_objects = get_field('field');
   if($post_objects!=''){ ?>
   <?php foreach( $post_objects as $post): ?>
   <?php setup_postdata($post); ?>
       <a href="<?php the_permalink(); ?>">
           <?php the_title(); ?>, 
       </a>
   <?php endforeach; ?>
<?php wp_reset_postdata(); ?>

This works for now but is not very pretty as it returns the values as "Value, Value, Value,". What I would like it to output is...

1 Value = "Value"

2 Values = "Value & Value"

3 or more Values = "Value, Value & Value"

"

2 Answers 2

0

Try to grab the output and echo together.

<?php $post_objects = get_field('field');
   if($post_objects!='') :
   $value = array(); ?>
   <?php foreach( $post_objects as $post): ?>
       <?php setup_postdata($post); ?>
       <?php $values[] = '<a href="'. get_permalink() .'">'. the_title('','',false) .'</a>'; ?>
   <?php endforeach; ?>
   <?php endif; ?>
<?php wp_reset_postdata(); ?>

<?php echo join( ', ', $values); ?>
0

You can use the number_format function of PHP.

You will get something like 2,500

<div>
  <?php if (get_field('events_price_yen')) { ?>
     <p>
        <?php $english_format_number = number_format(get_field('events_price_yen'));
              echo $english_format_number; ?>
     </p>
  <?php }; ?>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.