Last active
February 3, 2024 03:01
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage in Bricks:
{echo:get_associated_rm_profile_picture_url({post_id})}