Retrieving value from ACF Custom Field in Custom PHP Theme Pattern
-
Hi all,
I’m in Gutenberg editor with a FSE / Block Theme and I’m struggling to retrieve values from an ACF custom text field called ‘test’ in a new custom PHP pattern I created called ‘credits-list.php’ (located in my theme’s ‘patterns’ folder). I’m trying to retrieve this ‘test’ field in the pattern’s code using a get_field(‘test’) function. I’ve also tried the_field(‘test’) as well.
For testing, I’ve been adding this pattern to a custom post type (made using CPT UI) called ‘work’, and only a blank paragraph box has been showing, which it should show the default string ‘tester’. This leads me to believe that null is being returned from the PHP code in the pattern.
Any ideas on how I can properly access the ACF custom field value for a given ‘work’ post in this .php theme pattern? I don’t have ACF Pro (if that’s required in this instance..). For context, I’m using a child theme I created from Frost.
// credits-list.php
<?php
/**
* Title: Credits List
* Slug: squeake/credits-list
* Categories: text
* Description: A credit list for a piece of work.
*/
?>
<!-- wp:group {"align":"wide","layout":{"type":"constrained"}} -->
<div class="wp-block-group alignwide">
<!-- wp:paragraph {"align":"center","style":{"typography":{"lineHeight":"1"}},"fontSize":"max-23"} -->
<p>
<?php
$text = get_field('test');
echo $text;
?>
</p>
<!-- /wp:paragraph -->
</div>
<!-- /wp:group -->
The topic ‘Retrieving value from ACF Custom Field in Custom PHP Theme Pattern’ is closed to new replies.