Home › Forums › Front-end Issues › custom field applied to "page" not seen in archive-page › Reply To: custom field applied to "page" not seen in archive-page
Outside of “The Loop” which is where the header is, you need to tell ACF what $post_id you want to use get_field('field_name', $page_id);
$page_id can take many forms form an actual post id to a user to a term. This is covered on https://www.advancedcustomfields.com/resources/get_field/ in the section Get a value from different objects.
How you get the post ID for the current page depends on what you’re trying to get. For example an archive page is generally associated with a term
$post_id = 0;
$queried_object = get_queried_object();
if (isset($queried_ojbect->term_id)) {
$post_id = 'term_'.$term_id;
}
and this will only work if you have a custom field associated with the term in question.
For most “archive” pages, there isn’t anywhere to put a custom field. Archive pages outside of terms do not have an admin page, so there isn’t any way to add a field to a specific archive. In this case the best option is an options page that is associated with a specific post type.
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.