Question

i want to get multiple custom field from wordpress with one line for example. I have field "link","link1","link2","link3","link4" and "link_titull","link_titull1","link_titull2","link_titull3","link_titull4"

I have the code to get just one field and if its not filled its showing empty.

<?php $prop_det_url = get_field('link');
 if($prop_det_url!=''){ ?>
   <a href="<?php echo $prop_det_url; ?>" target="_blank">&gt; <?php the_field('link_titull'); ?></a>
   </p>
 <?php } ?>
Was it helpful?

Solution

<?php 
for( $i=1; $i<=4; $i++){
    $prop_det_url = get_field('link'.$i);
    if( $prop_det_url != '' ){ ?>
    <a href="<?php echo $prop_det_url; ?>" target="_blank">&gt; <?php the_field('link_titul'.$i); ?></a>
    <?php } 
}
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top