最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Getting ACF Field in Page - From the Footer

programmeradmin1浏览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 ( ) 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?

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/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?

Share Improve this question asked Jul 16, 2019 at 21:12 KennyKenny 1255 bronze badges 1
  • Are you sure the field name is hours-o-mo and that the post has a value for that field? – Sally CJ Commented Jul 17, 2019 at 6:42
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论