Hi Elliot,
The extra fields are to extend the WP standard user. After doing a remake of a large local government site a few years ago I like to try and keep all ‘people’ in one place.
After a bit of mucking around I got that to work. For the benefit of anyone else doing this here’s the code.
<?php if(get_field('people')): ?>
<?php while(has_sub_field('people')): ?>
<ul class="person">
<?php $person=get_sub_field('person'); ?>
<?php $person_id=$person['ID'];
$cell = get_field('cell', "user_{$person_id}");
$phone = get_field('phone', "user_{$person_id}");
$firstname=$person['user_firstname'];
$lastname=$person['user_lastname'];
$email=$person['user_email'];
$userid=get_field('user_{$person_id');
echo $personid;
?>
<li> <?php echo get_avatar( $email, $size, $default, $alt ); ?> </li>
<li class="persondetails">
<?php echo $firstname; ?>
<?php echo $lastname; ?>
<?php echo $email; ?>
<?php if ($cell != '0'){ ?>Cell: 0<?php echo $cell; ?><?php } else {} ?>
<?php if ($phone != '0'){ ?>Phone: <?php echo $phone; ?><?php } else {} ?>
<?php the_sub_field('person=>user_lastname'); ?>
<a href="<?php echo get_edit_user_link($person_id); ?>">edit person</a>
</li>
</ul>
<?php endwhile; ?>
<?php endif; ?>
The number fields seem to strip leading zeros and default to zero. Not sure if there’s a more sensible way of dealing with phone numbers, but this seems to work ok for me.
I wasn’t sure about using ‘user’ as a field name. It’s not a reserved word, but having multiple ‘user’ labels can make things pretty confusing.
I hate to admit it, but my filter at present is just this:
<?php
function my_acf_relationship_result( $html, $post )
{
// add an image to each result
$image = get_field('thumbnail', $post->ID);
$date = get_the_date();
if( $image )
{
$html = '<img src="' . $image['url'] . '" />' . $html;
}
return $html . ' ' . $date;
}
// acf/fields/relationship/result - filter for every field
add_filter('acf/fields/relationship/result', 'my_acf_relationship_result', 10, 2);
?>
and I’ve edited core/fields/relationship.php to change the sort order.
Not ideal, I know, but I needed it to work quickly.
Thanks. Could you add an example to show how to do this?
Pbolger
Hi Elliot,
Displaying the date is a good first step, but having the items spread alphabetically over a 500 entry list is going to make getting stories for this weeks newsletter a complete pain. If you could add sort by publish date it’d make things a hell of a lot easier.
Paul
This plugin:
http://www.cssigniter.com/ignite/custom-post-types-relationships/
Has a much better browse interface (too bad it doesn’t seem to work with WP3.6).
What are the chances of getting the ACF browse interface upgraded to something like this?
Next question: Can you change the order that the browse list is sorted by? Looks like it’s alphabetical, which is going to get really annoying for anyone trying to find ten posts in a list of 500.
I’ve found this
http://www.advancedcustomfields.com/resources/tutorials/customize-the-relationship-field-list-htm/
Would it be possible to hack that to display a date instead of an image?
(Using relationships instead of post objects, of course)
-answer: yes.
function my_acf_relationship_result( $html, $post )
{
// add an image to each result
$image = get_field('thumbnail', $post->ID);
$date = get_the_date();
if( $image )
{
$html = '<img src="' . $image['url'] . '" />' . $html;
}
return $html . ' ' . $date;
}
// acf/fields/relationship/result - filter for every field
add_filter('acf/fields/relationship/result', 'my_acf_relationship_result', 10, 2);
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!
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.