Home › Forums › General Issues › Relationship field query customization › Reply To: Relationship field query customization
I did something very similar recently. The code below basically queries the field ‘events’ for a list of events the user is associated with then adds the list to an array to use with the ‘include’ argument in the wp_query. Hope this snippet points you in the right direction
function my_post_object_results_for_specific_user( $args, $field, $post )
{
global $current_user, $wp_roles; get_currentuserinfo();
$user_id = $current_user->ID;
$events = get_field('events', 'user_'.$user_id );
$event_info = array();
foreach( $events as $event){
$event_info[] = $event->ID;
}
$args['include'] = $event_info;
return $args;
}
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.