Home › Forums › General Issues › How to pass variable to the_field? › Reply To: How to pass variable to the_field?
First the_field()
is only used to display fields. To use the value of the field somewhere else you need to use get_field()
You also need the post ID of the post where that other field appears. Basically, what you need is a post object field that returns the ID and the field name you want to put from that page.
Then, in long form
// get the field and post ID from this post
$field_name = get_field('field name of field containing field name');
$post_id = get_field('field name of post object field that has the above field');
// show the value from that other post
the_field($field_name, $post_id);
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 use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.