How to display custom field data from a different page

ACF Featured Image
noe
September 16, 2024

If you've ever wanted to use the custom fields data from one page on a different page, I'll show you how in this quick tutorial.

Example implementation

Lots of sites use ACF or ACF Pro to enable content management features. Often times, it's data pertaining to a specific page, but what do you do if you want to use the input text from one page and on a different page?

How not to do it

You might be thinking you could just duplicate the fields group and assign it to the other page. That way would work but is not the most efficient way.

In programming there's this concept called DRY or Don't Repeat Yourself.

By doing it this way, you're going to end up having to manage 2 sets of fields in 2 different places and map them to 2 different pages.

Ideally, we want to use the same fields as long as the data inside of them will remain the same side wide.

So a general rule of thumb, if you don't need 2 totally different sets of data, use the same if possible.

The better way to do it

ACF has a built in way to do this and it's very easy. All you have to do is utilize another parameter for the Page ID.

In custom theme development with ACF, you access the field data with get_field() assign it to a variable and echo it to display the field data.

Implementation would look like this

$value = get_field( "text_field", 123 );

We assign the value of text_field from post ID 123 and store it in the value variable.

Where text_field will be the name of your field found when editing the field group in ACF

And the post ID 123 will be the ID of the page or post. It can be either page or post including any custom post type.

Here's how you find the ID.

So then our modified get_field function will look like this:

$value = get_field( "call_to_action", 880 );

Now in my template, I just call $value wherever you want to display the data from the post field.

And that's it!

Have fun being efficient 🙂

p.s What did I miss? Are there any gaps in this post that you still don't understand? LMK.

Noes Logo
Learn more to earn more using WordPress. Practical ways to level up your skills fast.
Get In Touch:
Email: noe@noejunior.com