Oxygen Builder Tutorial

Retrieve an ACF User Field and Add it to the Post Template

Get Help with Oxygen
Blue globe and ball image
Categories:
Retrieve an ACF user field and add it to a post template

You can use Advanced Custom Fields, ACF, to add fields to your users in the WordPress admin area, which is great! However, Oxygen's ACF integration can't yet retrieve data from those fields. This tutorial will cover retrieving an ACF field for the current post author and adding it to Oxygen dynamically. This tutorial assumes that you will already have assigned an ACF field group to your users.

First off, you will need to install your favourite scripts plugin, such as Advanced Scripts (paid) or Code Snippets (free). I personally use Advanced Scripts as I think the interface is fantastic, but prior to that, I'd used Code Snippets for a number of years.

Since writing this tutorial, one of my friends has released a snippet plugin called WPCodeBox. It has cloud-based snippet storage, and is now my snippet plugin of choice.

Once you've installed the scripts plugin of your choice, you can create a new snippet with the following code:

function my_get_user_field($field) {
    $author_id = get_the_author_meta( 'ID' );  
    $user = "user_" . $author_id;
    $acf_info = get_field($field, $user);
    return $acf_info;
}

Next, edit your posts template. To retrieve your ACF author field, you need to use Dynamic Data > PHP Function Return Value. Enter the function name my_get_user_field, and in the arguments box, enter the name of the ACF field that you want to retrieve.

You can see an example of how to do this here:

You should then see your ACF data shown in your Oxygen template.

Phe Simmonds

Tutorial written by Phe Simmonds

Director & Web Developer at WinuSoft Web Design. When she's not working, Phe can usually be found mountain biking with her partner, Luis and dog, Bubba.
Blue background image Blue ball image

Other Tutorials

Blue circular lines

Get In Touch

Whether your business is just getting started or you’re in the middle of a growth spurt, we can design and develop a website that will help you scale.

"*" indicates required fields

Name*
This field is for validation purposes and should be left unchanged.
Copyright © 2024 WinuSoft Web Design
crosschevron-downarrow-right