Skip to content

Instantly share code, notes, and snippets.

@gsibert
Last active February 3, 2024 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsibert/6db44bcf48980569c9cf763f33e520dc to your computer and use it in GitHub Desktop.
Save gsibert/6db44bcf48980569c9cf763f33e520dc to your computer and use it in GitHub Desktop.
Gets the profile picture URL of a user from the ACF custom field profile_picture.
<?php
function get_associated_rm_profile_picture_url($post_id) {
// Get the user object related to this residential post
$residential_manager = get_field('residential_manager', $post_id);
// Proceed if we have a residential manager defined
if ($residential_manager) {
// Check if 'residential_manager' returns a User Object and extract the user ID
$user_id = is_array($residential_manager) && isset($residential_manager['ID']) ? $residential_manager['ID'] : null;
// If we have a user ID, get the profile picture
if ($user_id) {
$profile_picture = get_field('profile_picture', 'user_' . $user_id);
// Check if the profile picture exists and return its URL
if ($profile_picture && isset($profile_picture['url'])) {
return $profile_picture['url'];
}
}
}
// Return a default image URL or null if no profile picture is associated
return $profile_picture[url]; // Adjust this path to your default image
}
@gsibert
Copy link
Author

gsibert commented Feb 3, 2024

Usage in Bricks:
{echo:get_associated_rm_profile_picture_url({post_id})}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment