0

I'm trying to get ACF field that is part of an ACF block in a Page I've created, say "Home Page". I'm trying to do this from the footer, but with no success.

I've tried the following:

I got the "post" id (despite it's a page) from the url in the admin console: /wp-admin/post.php?post=7&action=edit. My code may seem strange, it's a php blade template, I'm using Root.io Sage theme.

{{ the_field('hours-o-mo', 7) }}

and

@php
    the_field('hours-o-mo', 7) 
@endphp 

I haven't "registered" any blocks, per se, I'm just using this plugin ( https://github.com/MWDelaney/sage-acf-wp-blocks ) to make template-only acf blocks, that automatically show in my Gutenberg page builder.

I've also tried get_field. I'm not sure what I'm doing wrong, it should be simple to get an ACF field from a specific page, from the footer. Right?

1
  • Are you sure the field name is hours-o-mo and that the post has a value for that field?
    – Sally CJ
    Jul 17, 2019 at 6:42

1 Answer 1

1

I have the same issue, the acf get_field() function in footer returned null. Native WP function get_post_meta( get_the_ID(), 'option_key', true ) didn't work to. But when I've noticed that get_the_ID() function in footer returned the wrong value because I forgot to reset query after custom WP_Query. So, reset custom WP_Query (wp_reset_query()) or hard code the page ID.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.