How to output custom user fields in Oxygen

le 26/10/2021
JAG

In Oxygen’s Facebook group, a user asks:
I just added a custom field through ACF (free version) to the user add/edit page. It shows up and I’m able to add data (it’s a “Position” field for the position in the company). I can’t for the life of me figure out how to pull in this field via Oxygen. The post custom fields shows it but, since it’s not a post field, it’s blank.Any ideas? Thanks in advance!I’m using it on a template I created for blog posts. I laid it out with Author Pic, Author name, and I want author title. I removed sanitization from the bio and am coding what I want to show there but it’d be nice to find a way for ACF to work from the user profile.
We can create a function that takes in the name of a custom field linked to the user that returns the corresponding value for the current entry’s author. Then call it using the Oxygen‘s dynamic data insertion feature.
Sample screenshots:
in the profile page
value of “position” user field on the single post in parentheses
Step 1
Install and activate Advanced Custom Fields or ACF Pro.
Go to Custom Fields > Add New.
Add a new field group named say, “Additional Info”.
Let’s add a new text-type field having the label of “Position” i.e., a field name of position.
Set the field group to show if User Role is equal to All (or to specific user roles as needed).

Step 2
Install and activate Code Snippets.
Go to Snippets > Add New.
Title: Return value of post author’s custom user field
Code:
/**
* Returns the value of supplied user field.
* @param string $field_name Name of the custom field created using ACF.
* @return string Value of user field.
*/
function sk_get_author_custom_field( $field_name ) {

$author_id = get_the_author_meta( 'ID' );

return get_field( $field_name, 'user_' . $author_id );

}
To output a custom user ACF field named say, position for the current post’s author we can now call the above function like so in PHP:
sk_get_author_custom_field( 'position' ).
Step 3
Edit the Template for single Posts.
Add a Text element having this text: by author (position)
We shall replace “author” with the current post’s author name and “position” with the corresponding custom field value.
a) Double click on “author” text.
Click on “Insert Data” button at the top.
Under “Author”, click on “Display Name”.
Then click “Insert” button.
b) Double click on “position” text.
Click on “Insert Data” button at the top.
Under “Advanced”, click on “PHP Function Return value”.
Function Name: sk_get_author_custom_field
Function Arguments: position
Click the “Insert” button.

Click anywhere outside the text element and you should see the position of the author that wrote that post if it has been set.
That’s it!
Reference.

Nos experts se tiennent à votre disposition
pour répondre à vos questions et vous conseiller
dans votre projet digital.

Vous souhaitez développer une application ?

Envie d’échanger avec l’un de nos experts ? Besoin d’en savoir plus ?
En savoir plus

Recevez notre newsletter

La protection des données nous tient à cœur. JAG utilise les informations que vous fournissez afin de vous proposer des informations et du contenu pertinent sur nos produits et services. Vous pouvez vous désinscrire de ce type de communications à tout moment. Pour plus d'informations, consultez notre politique de confidentialité
© 2022 JAG Consulting, sas. Tous droits réservés.
© 2022 JAG Consulting, sas. Tous droits réservés.
4.8
Lire les 51 avis
google
Brieuc Pauly
08/09/2022

Créative, dynamique et très professionnelle, c'est à mon sens les piliers qui soutiennent cette équipe talentueuse ! Une agence à taille humaine qui privilégie la qualité et le résultat. Alors si vous souhaitez le meilleur pour votre communication adressez vous les yeux fermés à ces passionnés, plus que compétents ! (Translated by Google) Creative, dynamic and very professional, these are in my opinion the pillars that support this talented team! A human-sized agency that favors quality and results. So if you want the best for your communication, turn your eyes closed to these enthusiasts, who are more than competent!

google
Amaury Tardier
08/09/2022

Merci à Julien et son équipe, plus que satisfait par le travail fourni ! Je recommande vivement ! (Translated by Google) Thanks to Julien and his team, more than satisfied with the work provided! I highly recommend !

Ravi de travailler avec l'équipe JAG pour la gestion de mon site de e-Commerce. Equipe réactive et toujours pleine de bonnes idées pour améliorer les performances du site (Translated by Google) Glad to work with the JAG team for the management of my e-Commerce site. Responsive team always full of good ideas to improve the performance of the site

Merci à Julien pour son accompagnement dans mon projet, je recommande à 200% c est le Top (Translated by Google) Thanks to Julien for his support in my project, I recommend 200% it is the top

Excellente agence. Equipe est très pro, à l'écoute et de bon conseils. (Translated by Google) Excellent agency. The team is very professional, attentive and gives good advice.

Temps de réponse hors pair quand il y a eu un pb sur mon site, je vous recommande chaleureusement Julien :-) (Translated by Google) Unparalleled response time when there was a problem on my site, I warmly recommend Julien :-)

Charger plus
listarrow-right
Julien

Julien

Votre conseiller

I will be back soon

Une question ?

Julien
Bonjour ! Je suis Julien.
Comment puis-je vous aider?
Démarrer la conversation:
chat Live Chat