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) {
      string(96) "http://localhost:8888/"
      string(101) "http://localhost:8888/"
      string(96) "http://localhost:8888/"

    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?