Home Forums General Issues How to count Foreach > Field Users


How to count Foreach > Field Users

  • Hello,

    This is my problem, I created several ACF fields on my user accounts by ID.

    I made a foreach system to retrieve the members and the fields they filled in.
    Now I can’t count the field numbers of people who have been informed.

    For example I have 6 entries, of these 6 entries only 2 people have added their Discord ID, so I would like my foreach to return an echo to display statistics.

    Result example: 2 people disagree.

    Here is my code.
    Translated with

    $args = array(
        'number' => 50,
        'orderby' =>'registered',
        'order' => 'DESC'
    $my_user_query = new WP_User_Query( $args );
    $inscrits = $my_user_query->get_results();
    if ( ! empty( $inscrits ) ) {
            foreach ( $inscrits as $inscrit ) {
                $user_avatar = dg_get_image_url_by_id(get_field("avatar", "user_".$inscrit->ID), "medium");
                $user_discord_api = get_field("user_discord_api", "user_".$inscrit->ID);
                $user_background_image = dg_get_image_url_by_id(get_field("user_background_image", "user_".$inscrit->ID), "large");
                $inscrit_info = get_userdata( $inscrit->ID );
                $groupe_user = get_field("groupe_user", "user_".$inscrit->ID);
                $user_status =  get_field("user_status", "user_".$inscrit->ID);
      <div class="col-lg-3 <?php echo $groupe_user ;?> item">
                <div class="card profil-sc" style="
                    background:linear-gradient( rgb(37, 43, 51), rgba(206, 194, 194, 0) ),
                    url(<?php echo $user_background_image; ?>);
                   <a href="/membre/<?php echo $inscrit->user_nicename; ?>"><div class="useravatar">
                            <div style="background-image: url('<?php echo $user_avatar; ?>')"></div>
                    <div class="card-sc-pseudo">
                        <span class="card-title"><?php echo $inscrit->display_name; ?></span>
                    <div class="sc-nivel align-self-center">0</div>
                    <div class="sc-join align-self-center button-sc p-2 upper"><a href="/membre/<?php echo $inscrit->user_nicename; ?>">Voir le profil</a></div>
                  <div class="card-sc-footer">
                        <span class="card-title"><div class="status-<?php echo $groupe_user ;?>"><?php echo get_groupe_user($groupe_user); ?></div></span>
    function get_groupe_user($groupe_user){
      $status_list = array(
        "Leader" => "<i class=\"far fa-helmet-battle\"></i> Leader",
        "Streameur" => "<i class=\"fab fa-twitch\"></i>  Streameur",
        "Youtubeur" => "<i class=\"fab fa-youtube\"></i> Youtubeur",
        "Cosplayeur" => "<i class=\"fas fa-paint-brush\"></i> Cosplayeur",  
        "Gamer" => "<i class=\"far fa-gamepad\"></i> Gamer"
        return $status_list[$groupe_user];

    My Field Discord : $user_discord_api = get_field("user_discord_api", "user_".$inscrit->ID);

    Thanks for help <3 !

Viewing 1 post (of 1 total)

The topic ‘How to count Foreach > Field Users’ is closed to new replies.