I’m new to this just so you guys know. So I want to display all registered users on a template page.
what I have right now in my template is:
$member_type = (isset($member_type) ? $member_type : 'seb'); $post_type = $member_type == 'seb' ? array('companies', 'members') : 'companies'; $args = array( 'posts_per_page' => -1, 'post_type' => $post_type, 'meta_query' => array( array( 'key' => 'member_type', 'value' => $member_type, 'compare' => 'LIKE', ) ), 'orderby' => 'title', 'order' => 'ASC' ); if ($member_type == 'seb') { $args['meta_query']['relation'] = 'OR'; array_push( $args['meta_query'], array( 'key' => 'company', 'value' => '', 'compare' => '=' ) ); } $users = get_users( array( 'fields' => array( 'ID' ) ) ); foreach($users as $user_id){ print_r(get_user_meta ( $user_id->ID)); }
what I’m I doing wrong here.
Advertisement
Answer
You follow this link then you get users easily by using this function. I hope its beneficial for you. https://developer.wordpress.org/reference/functions/get_users/
$blogusers = get_users( array( 'fields' => array( 'display_name' ) ) ); // Array of stdClass objects. foreach ( $blogusers as $user ) { echo '<span>' . esc_html( $user->display_name ) . '</span>'; }