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?
You don't need nested PHP tags. Omit the php tags inside and your code should run.
Note the difference between
get_field
andthe_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:
get_field('one')
andreturn 1
.photo_gallery(1)
andreturn (photo)
.echo (photo)
There are some courses on PHP, many of which are free - that might help you sort through some of these issues.