Getting ACF Field in Page – From the Footer

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 … Read more

How to get ACF value inside Gutenberg Block from another page or template? I’m using Timber too

You’ll need to set a render callback when you create your ACF block: acf_register_block_type( array( ‘name’ => ‘example-block’, ‘title’ => __( ‘Example Block’, ‘your-text-domain’ ), ‘description’ => __( ‘A custom example block.’, ‘your-text-domain’ ), ‘render_callback’ => ‘my_acf_block_render_callback’, ‘category’ => ‘formatting’, ‘icon’ => ‘admin-comments’, ‘keywords’ => array( ‘example’ ), ) ); Then in that function you … Read more

Get ACF options field in PHP acting as CSS

I’m not sure what exactly your setup is or where this file is but ACF saves its values as post meta. So you could simply use WP’s get_post_meta() if ACF isn’t available. For Example: get_post_meta( get_the_ID(), ‘field_name’, true ); You can also have a look at this article, it talks about using get_post_meta vs ACF … Read more

ACF for custom post type archive pages: which hook to use?

Is this a sequence mismatch between the hooks? I would argue so, yes. acf/init gets executed by class ACF’s init method, all in the root file acf.php – this method is hooked to WordPress’ init with a priority of 5 like so add_action( ‘init’, array($this, ‘init’), 5 ); And you probably add your CPTs with … Read more

Create short URL with auto 301 redirect

What you’re trying to do, can be achived by simply using the parse_request hook; no need for the custom rewrite rule and tag. So remove this (and you should flush the rewrite rules — just visit the permalink settings page): add_action( ‘init’, ‘vacature_rewrite_rule’ ); function vacature_rewrite_rule() { … } Then use this modified function which … Read more

ACF save json to custom directory not working, default acf-json used instead

the two filters don’t have the same output. you can test that add_filter(‘acf/json_directory’, function ($path) { return get_template_directory() . ‘/config/acf-json’; }); add_filter(‘acf/settings/save_json’, function ($path) { return apply_filters(“acf/json_directory”, NULL); }); add_filter(‘acf/settings/load_json’, function ($paths) { return [ apply_filters(“acf/json_directory”, NULL) ]; });

Accessing values from ACF sub field (flexible content area) in PHP

You iterate through posts obtained by the get_posts(), so you have to pass post ID as the second parameter of the function have_rows(). By default ID of current post is used. foreach ($articles as $article) { $value = null; if( have_rows( ‘info_items’, $article->ID ) ): while( have_rows( ‘info_items’, $article->ID ) ): the_row(); $value = get_sub_field(‘info_location’); … Read more