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;