Home › Forums › Add-ons › Repeater Field › Calling in Custom Fields
I’m pretty new to this and need some basic help.
I have created a template for my page ‘stockists’, attached that to a page in wordpress (also stockists) and used advanced custom fields & repeater fields to add my content. When I visit the page in question in the back end of wordpress I can see my custom fields and edit them just fine.
When I ‘view page’ however, I see nothing. I’ve added the following code to the page-template.php:
<?php the_field ('stockists'); ?>
What am I doing wrong?
Thanks in advance to anyone who can help a newbie! 🙂
Have you put the code inside of the loop? The loop is the while loop looking something like:
<?php while(have_posts()): the_post(); ?>
<?php while(have_posts()): the_post(); ?> <p><?php the_field('stockists'); ?></p> <?php endwhile; ?>
My page displays the header and footer (just under the header) and it says ‘array, array’ where the page and it’s custom fields should be.
What kind of field is ‘stockists’?
From what you have posted, it looks liek the returned value is a bunch of array’s
Perhaps you need to read over the docs and see how to use the functions to render out the HTML into your template.
Thanks to both for your help. I was using the_repeater_field and only calling in the_field! Love that moment when the penny drops!
Glad you found a solution but perhaps you could provide a clearer explanation of the solution for other readers?
Sure. I purchased the add-on for “repeater” fields, to make it easier to add several lines of information.
The initial code above just calls in the field ‘stockists’ (the name of the ACF I created). What I needed to do was call in the ‘repeater_field’ followed by each repeated field. Here’s the correct code..
<?php while(the_repeater_field('stockists')): ?> <div class="stockists"><br /> <strong><?php the_sub_field('stockists_name'); ?></strong><br /> <?php the_sub_field('address'); ?><br /> <?php the_sub_field('address_2'); ?><br /> <?php the_sub_field('city'); ?><br /> <strong><?php the_sub_field('phone_number'); ?></strong><br /> <?php the_sub_field('website'); ?><br />
So ‘stockists’ was the original custom field. Name, address, city etc are the repeater fields.
The topic ‘Calling in Custom Fields’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re hard at work on ACF 6.1, and Beta 1 is now available 🚀— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.