How would I change the following function so that $user->ID would return all users ID’s one at a time?
It now only returns the first user with lowest ID, and then adds that ID to all following users.
Resulting in that all users get the same categories as the first user.
user_kategoriat is an ACF field: here’s what I’ve been looking at:
https://www.advancedcustomfields.com/resources/how-to-get-values-from-a-user/
add_filter( 'algolia_user_record', 'my_post_attributes', 10, 2 );
function my_post_attributes( $attributes ) {
$users = get_users( array( 'fields' => array( 'ID' ) ) );
foreach ( $users as $user ) {
$ID = $user->ID;
$attributes['kategoriat'] = get_field('user_kategoriat', 'user_'. $ID );
return $attributes;
}
}
2
Answers
Here is what worked:
return exits the loop. You can try this: