While using Advanced Custom Fields for Wordpress I got to call some vars using get_field('my-custom-field');
I got this code which I would like to store in a function:
<img src="<?php the_sub_field('image-1'); ?>">
<?php $target_post = get_sub_field('target-1'); ?>
<?php echo get_the_title($target_post); ?>
All I need to replace inside my function is the -1
to -2
, -3
, etc. How can I do this?
I have tried this, which does not work:
function imageBlock($fieldID = '1') {
<img src="<?php the_sub_field('image-$fieldID'); ?>">
<?php $target_post = get_sub_field('target-$fieldID'); ?>
<?php echo get_the_title($target_post); ?>
}
How can I pass the fieldID
to the get_field('my-custom-field-1');
function?