Home › Forums › Front-end Issues › get_fields() is fetching the wrong custom fields › Reply To: get_fields() is fetching the wrong custom fields
Thanks for the quick response! Though passing the page’s post ID as a parameter did in fact make get_fields() behave accordingly by fetching the page’s custom fields, the page’s behavior is still very, very weird. For instance when I output the Array that get_fields() fetches, everything looks normal I get an array that looks like this:
array(3) {
["jumbo_1"]=>
string(96) "http://localhost:8888/juanturcios.com/wp-content/uploads/2014/01/father-and-son-juan-turcios.jpg"
["jumbo_2"]=>
string(101) "http://localhost:8888/juanturcios.com/wp-content/uploads/2014/01/fashion-photography-juan-turcios.jpg"
["jumbo_3"]=>
string(96) "http://localhost:8888/juanturcios.com/wp-content/uploads/2014/01/wedding-brides-green-forest.jpg"
}
That means get_fields() is working properly. HOWEVER, when I go in and key into this array randomly (and again, the same code works in all pages except my blog index listing page home.php) and use the code’s output to generate the link for the banner’s background image, it is blank. Upon inspecting the div I can see that the background: url(”); is in fact blank. So then I decided to instead try to code it manually and used intead the function the_field(‘jumbo_1’) passing it the first image’s field name key so it would maybe display and nothing happened– still blank. Puzzled by this I decided to pass in the field name of a custom field that is available ONLY for single.php blog posts: the_field(‘slider_image_1’); which enables the user to upload an image for an image slider on every blog post. And to my surprise it did show up!
It’s so odd. It seems as if the blog listing page did not have access to its own custom fields (despite the fact that get_fields() is outputting the right field group array) and rather somehow the code can display fields that are not even allowed to be on the blog page.
Any insights on this? Should I change my field location rule logic somehow?
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.