Support

Account

Home Forums Backend Issues (wp-admin) Help with shortcode counting users based off ACF

Helping

Help with shortcode counting users based off ACF

  • I am trying to figure out how to count the number of users based off a field from ACF. In the past I have used something similar to this for default fields. But in this example, I always get 1, even though that is not the count. I don’t understand, is there something I need to do different for ACF? I’ve tried setting the value to Associate Member:associate_member for the dropdown list and changing the value in the script, but that just doesn’t work at all.


    add_shortcode( 'show_assocaite_member', 'associate_member_count' ); //Count users
    function associate_member_count() {
    $aargs = array(
    'meta_key' => 'membership_type', //any custom field name
    'meta_value' => 'Associate Member', //the value to compare against
    );
    $ausers= new WP_User_Query( $aargs );
    return $ausers->get_total();
    }

  • I’ve looked through the wp docs and I don’t see any reason this should not be working, unless it’s just not finding any matches. Are you sure about the meta_key and meta_value values? Is it possible that these are sub fields of a group field or a repeater?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.