I use the plugin "types" for WP. required from the admin to add and delete phones on the site. Created an additional field, allowed him multiple values ​​(phone numbers can be several at the same time). When I try to display a field, I get all the values ​​in a heap, I output it like this:

echo types_render_field('tel'); 

Those. if there are 2 fields with the numbers "1111" and "2222", then "11112222" is displayed. Previously, the problem was solved by a separator:

 types_render_field('tel', array (separator => '<br>')); 

But now you need to make sure that each phone number is wrapped in a clickable link:

 <a href = 'tel:1111'>1111</a> <br> <a href = 'tel:2222'>2222</a> 

and the separator does not save. Maybe someone knows how to divide the values ​​so that they can be a cycle to deduce for example

  • <a href="<?= echo types_render_field('tel'); ?> "> types_render_field ('tel', array (separator => '</a> <br>')); as an option: DDD - Lieutenant Jim Dangle
  • or do a loop in this way tel-i; at the end of the i ++ cycle and it’s natural to call the fields thus tel-1, tel-2 ... - Lieutenant Jim Dangle
  • Thanks for the answer, the first option will not work. <? = echo types_render_field ('tel'); ?> immediately in the link will give both values ​​and the second number will be without a link, and the second will not work because of inconvenience, the mod will not climb the plugin and look for where to add or remove a field - Alexander

1 answer 1

The solution is found, the string is converted to an array, and then it is looped. Suddenly someone come in handy

 while (have_posts()) { the_post(); $tel = (string)types_render_field('tel'); $arr = explode(' ', $tel); foreach ($arr as $key => $value) { echo "<a href=\"tel: {$value}\">{$value}</a><br>"; } }