Hey, there! I’m tryng to create a staff page that displays all users with the role “editor” on this website. I’ve got a start here:
http://annex.gocopilot.org/about/staff/
Where I’m stumped is how to add the ACF fields I’ve added to the Users. I was able to display them successfully on the “Author Archive” page, but now I’d like to pull in two custom images and a custom field with the job title and everything I’ve tried to pull that data has failed.
The field names are:
title
regpho (a photo array)
hovpho (a photo array
Here’s the code in the functions file I’m currently using (you’ll notice I tried to pull in title; however, it’s not displayng at all so there’s certainly something I’m doing wrong! Thanks in advance for your help!
/*STAFF DIRECTORY*/
function stadir() {
?>
<?php
$display_admins = false;
$order_by = ‘display_name’; // ‘nicename’, ’email’, ‘url’, ‘registered’, ‘display_name’, or ‘post_count’
$order = ‘DESC’;
$role = ‘editor’; // ‘subscriber’, ‘contributor’, ‘editor’, ‘author’ – leave blank for ‘all’
$avatar_size = 161;
$hide_empty = false; // hides authors with zero posts
if(!empty($display_admins)) {
$blogusers = get_users(‘orderby=’.$order_by.’&role=’.$role);
} else {
$admins = get_users(‘role=administrator’);
$exclude = array();
foreach($admins as $ad) {
$exclude[] = $ad->ID;
}
$exclude = implode(‘,’, $exclude);
$blogusers = get_users(‘exclude=’.$exclude.’&orderby=’.$order_by.’&order=’.$order.’&role=’.$role);
}
$authors = array();
foreach ($blogusers as $bloguser) {
$user = get_userdata($bloguser->ID);
if(!empty($hide_empty)) {
$numposts = count_user_posts($user->ID);
if($numposts < 1) continue;
}
$authors[] = (array) $user;
}
echo ‘<ul id=”grid-contributors”>’;
foreach($authors as $author) {
$avatar = get_avatar($author[‘ID’], $avatar_size);
$author_title = get_field( $author[‘ID’], title );
$display_name = $author[‘data’]->display_name;
$author_profile_url = get_author_posts_url($author[‘ID’]);
echo ‘<li class=”single-item”>’;
echo ‘<div class=”author-gravatar”>‘, $avatar , ‘</div>’;
echo ‘<div class=”author-name”>‘, $display_name, ‘</div>’;
echo ‘<div class=”author-name”>‘, $author_title, ‘</div>’;
echo ‘‘;
}
echo ‘‘;
?>
<?php
}
add_action(‘hook_top_stadir’, ‘stadir’);
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.