This is my code to echo ACF fields if a taxonomy
<?php
$terms = get_the_terms( $post->ID , 'agents' );
$socials = get_field('ag_social', $terms);
print_r($socials);
?>
the result is this: ( [0] => Array ( [ag_telegram] => https://t.me/+xx [ag_whatsapp] => https://wa.me/xxx [ag_insta] => https://instagram.com/x ) )
can anyone help me to print each field separately
for telegram ex: https://t.me/+xx
for whatsapp ex: https://wa.me/xxx
for instagram ex: https://instagram.com/x
Thanks
My Answer:
You can access each field separately by using the array key. Here's how you can print each field separately:
php
$terms = get_the_terms( $post->ID , 'agents' );
$socials = get_field('ag_social', $terms);
echo 'Telegram: ' . $socials[0]['ag_telegram'] . '
';
echo 'Whatsapp: ' . $socials[0]['ag_whatsapp'] . '
';
echo 'Instagram: ' . $socials[0]['ag_insta'] . '
';
?>
This code will output the values of each field separately. Just replace the keys with the actual keys in your ACF repeater field.
Rate this post
4 of 5 based on 9715 votesComments