I have a code which returns gallery number 1 with the set of images.
<?php echo photo_gallery(1); ?>
But I need to change number "1" to number "2", "3" and so on with custom fields in every post using this code
<?php the_field('number'); ?>
inside the first code
I need something like this:
<?php echo photo_gallery( <?php the_field('number'); ?> ); ?>
Result:
<?php echo photo_gallery(2); ?>
or
<?php echo photo_gallery(3); ?>
Something like this?
<?php
echo photo_gallery(the_field('images'));
?>
You don't need nested PHP tags. Omit the php tags inside and your code should run.
<?php
echo photo_gallery(get_field('number'));
?>
Note the difference between get_field
and the_field
. ACF docs explain which to use in which situation.
Essentially, the functions inside (to the right) get executed first, returning a value which can be used by the outer function (to the left).
In the background, a programming language takes these steps:
- execute
get_field('one')
and return 1
.
- execute
photo_gallery(1)
and return (photo)
.
echo (photo)
There are some courses on PHP, many of which are free - that might help you sort through some of these issues.