Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

I'm using human made's custom meta boxes framework (https://github.com/humanmade/Custom-Meta-Boxes). I want to add a select drop down in my metabox wich is populated from the users with multiple roles on my WP site. Referencing this post : Get multiple roles with get_usersGet multiple roles with get_users

I came up with:

add_filter( 'cmb_meta_boxes', 'users_metabox' ); function eusers_metabox( array $meta_boxes ) { $prefix = 'user_'; global $wpdb; $blog_id = get_current_blog_id(); $user_query = new WP_User_Query( array( 'meta_query' => array( 'relation' => 'OR', array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Administrator', 'compare' => 'like' ), array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Editor', 'compare' => 'like' ) ) ) ); $fields = array( array( 'id' => $prefix . 'user_sub', 'name' => 'Subscriber User', 'type' => 'select', 'use_ajax' => false, 'options' => $user_query, // this is where you populate the select in metabox ), ); $meta_boxes[] = array( 'title' => 'Location Info', 'pages' => 'em_users', 'context' => 'normal', 'priority' => 'high', 'fields' => $fields ); return $meta_boxes; } 

Works somewhat, but seems to return just capital letters. Any ideas?

Need to output (UserID) as variable constant

I'm using human made's custom meta boxes framework (https://github.com/humanmade/Custom-Meta-Boxes). I want to add a select drop down in my metabox wich is populated from the users with multiple roles on my WP site. Referencing this post : Get multiple roles with get_users

I came up with:

add_filter( 'cmb_meta_boxes', 'users_metabox' ); function eusers_metabox( array $meta_boxes ) { $prefix = 'user_'; global $wpdb; $blog_id = get_current_blog_id(); $user_query = new WP_User_Query( array( 'meta_query' => array( 'relation' => 'OR', array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Administrator', 'compare' => 'like' ), array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Editor', 'compare' => 'like' ) ) ) ); $fields = array( array( 'id' => $prefix . 'user_sub', 'name' => 'Subscriber User', 'type' => 'select', 'use_ajax' => false, 'options' => $user_query, // this is where you populate the select in metabox ), ); $meta_boxes[] = array( 'title' => 'Location Info', 'pages' => 'em_users', 'context' => 'normal', 'priority' => 'high', 'fields' => $fields ); return $meta_boxes; } 

Works somewhat, but seems to return just capital letters. Any ideas?

Need to output (UserID) as variable constant

I'm using human made's custom meta boxes framework (https://github.com/humanmade/Custom-Meta-Boxes). I want to add a select drop down in my metabox wich is populated from the users with multiple roles on my WP site. Referencing this post : Get multiple roles with get_users

I came up with:

add_filter( 'cmb_meta_boxes', 'users_metabox' ); function eusers_metabox( array $meta_boxes ) { $prefix = 'user_'; global $wpdb; $blog_id = get_current_blog_id(); $user_query = new WP_User_Query( array( 'meta_query' => array( 'relation' => 'OR', array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Administrator', 'compare' => 'like' ), array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Editor', 'compare' => 'like' ) ) ) ); $fields = array( array( 'id' => $prefix . 'user_sub', 'name' => 'Subscriber User', 'type' => 'select', 'use_ajax' => false, 'options' => $user_query, // this is where you populate the select in metabox ), ); $meta_boxes[] = array( 'title' => 'Location Info', 'pages' => 'em_users', 'context' => 'normal', 'priority' => 'high', 'fields' => $fields ); return $meta_boxes; } 

Works somewhat, but seems to return just capital letters. Any ideas?

Need to output (UserID) as variable constant

added 50 characters in body; edited title
Source Link
Rizzo
  • 269
  • 6
  • 20

HM CMB: Users Select inside custom metabox

I'm using human made's custom meta boxes framework (https://github.com/humanmade/Custom-Meta-Boxes). I want to add a select drop down in my metabox wich is populated from the users with multiple roles on my WP site. Referencing this post : Get multiple roles with get_users

I came up with:

add_filter( 'cmb_meta_boxes', 'users_metabox' ); function eusers_metabox( array $meta_boxes ) { $prefix = 'user_'; global $wpdb; $blog_id = get_current_blog_id(); $user_query = new WP_User_Query( array( 'meta_query' => array( 'relation' => 'OR', array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Administrator', 'compare' => 'like' ), array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Editor', 'compare' => 'like' ) ) ) ); $fields = array( array( 'id' => $prefix . 'user_sub', 'name' => 'Subscriber User', 'type' => 'select', 'use_ajax' => false, 'options' => $user_query, // this is where you populate the select in metabox ), ); $meta_boxes[] = array( 'title' => 'Location Info', 'pages' => 'em_users', 'context' => 'normal', 'priority' => 'high', 'fields' => $fields ); return $meta_boxes; } 

Works somewhat, but seems to return just capital letters. Any ideas?

Need to output (UserID) as variable constant

HM CMB: Users Select

I'm using human made's custom meta boxes framework (https://github.com/humanmade/Custom-Meta-Boxes). I want to add a select drop down in my metabox wich is populated from the users with multiple roles on my WP site. Referencing this post : Get multiple roles with get_users

I came up with:

add_filter( 'cmb_meta_boxes', 'users_metabox' ); function eusers_metabox( array $meta_boxes ) { $prefix = 'user_'; global $wpdb; $blog_id = get_current_blog_id(); $user_query = new WP_User_Query( array( 'meta_query' => array( 'relation' => 'OR', array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Administrator', 'compare' => 'like' ), array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Editor', 'compare' => 'like' ) ) ) ); $fields = array( array( 'id' => $prefix . 'user_sub', 'name' => 'Subscriber User', 'type' => 'select', 'use_ajax' => false, 'options' => $user_query, // this is where you populate the select in metabox ), ); $meta_boxes[] = array( 'title' => 'Location Info', 'pages' => 'em_users', 'context' => 'normal', 'priority' => 'high', 'fields' => $fields ); return $meta_boxes; } 

Works somewhat, but seems to return just capital letters. Any ideas?

Users Select inside custom metabox

I'm using human made's custom meta boxes framework (https://github.com/humanmade/Custom-Meta-Boxes). I want to add a select drop down in my metabox wich is populated from the users with multiple roles on my WP site. Referencing this post : Get multiple roles with get_users

I came up with:

add_filter( 'cmb_meta_boxes', 'users_metabox' ); function eusers_metabox( array $meta_boxes ) { $prefix = 'user_'; global $wpdb; $blog_id = get_current_blog_id(); $user_query = new WP_User_Query( array( 'meta_query' => array( 'relation' => 'OR', array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Administrator', 'compare' => 'like' ), array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Editor', 'compare' => 'like' ) ) ) ); $fields = array( array( 'id' => $prefix . 'user_sub', 'name' => 'Subscriber User', 'type' => 'select', 'use_ajax' => false, 'options' => $user_query, // this is where you populate the select in metabox ), ); $meta_boxes[] = array( 'title' => 'Location Info', 'pages' => 'em_users', 'context' => 'normal', 'priority' => 'high', 'fields' => $fields ); return $meta_boxes; } 

Works somewhat, but seems to return just capital letters. Any ideas?

Need to output (UserID) as variable constant

Source Link
Rizzo
  • 269
  • 6
  • 20

HM CMB: Users Select

I'm using human made's custom meta boxes framework (https://github.com/humanmade/Custom-Meta-Boxes). I want to add a select drop down in my metabox wich is populated from the users with multiple roles on my WP site. Referencing this post : Get multiple roles with get_users

I came up with:

add_filter( 'cmb_meta_boxes', 'users_metabox' ); function eusers_metabox( array $meta_boxes ) { $prefix = 'user_'; global $wpdb; $blog_id = get_current_blog_id(); $user_query = new WP_User_Query( array( 'meta_query' => array( 'relation' => 'OR', array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Administrator', 'compare' => 'like' ), array( 'key' => $wpdb->get_blog_prefix( $blog_id ) . 'capabilities', 'value' => 'Editor', 'compare' => 'like' ) ) ) ); $fields = array( array( 'id' => $prefix . 'user_sub', 'name' => 'Subscriber User', 'type' => 'select', 'use_ajax' => false, 'options' => $user_query, // this is where you populate the select in metabox ), ); $meta_boxes[] = array( 'title' => 'Location Info', 'pages' => 'em_users', 'context' => 'normal', 'priority' => 'high', 'fields' => $fields ); return $meta_boxes; } 

Works somewhat, but seems to return just capital letters. Any ideas?