Separate [Advanced Custom Field] values by commas

I have a 'relationship' custom field that allows you to select multiple values and display them via<?php $p

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"

"

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"

"

Share Improve this question asked Dec 21, 2013 at 1:48 SBMSBM 721 silver badge7 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 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); ?>

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745340941a4623322.html

相关推荐

  • Separate [Advanced Custom Field] values by commas

    I have a 'relationship' custom field that allows you to select multiple values and display them via<?php $p

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信