Published on Mar 12, 2021

[Screencast] ACF User Fields for Current User in Oxygen

Sridhar Katakam

This video shows how to register a couple of custom fields using Advanced Custom Fields incl. True / False type that are attached to user forms and display their values for currently logged in user conditionally in Oxygen.

Code:

<?php
$has_server = get_field( 'has_server', 'user_' . get_current_user_id() );
if ( $has_server ) {
$server_url = get_field( 'server_url', 'user_' . get_current_user_id() );
}
if ( $server_url ) {
echo 'Your server URL is: ' . $server_url;
} else {
echo 'You do not have a server!';
}
?>

or

<?php
echo ( get_field( 'has_server', 'user_' . get_current_user_id() ) ) ? 'Your server URL is: ' . get_field( 'server_url', 'user_' . get_current_user_id() ) : 'You do not have a server!';
?>

Context

References

https://www.advancedcustomfields.com/resources/how-to-get-values-from-a-user/

https://www.advancedcustomfields.com/resources/true-false/

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right