I'm building an intranet where I want users to be able to email other groups of users. I've successfully created a function that returns a list of user emails depending on their meta data (which are passed as arguments).
But I need help creating shortcodes. For example, a shortcode that outputs a mailing-list of all the users that have blue as a favorite color (data from a user registration form).
I've tried the simple add_shortcode('$tag , $func') but since I need to pass arguments that doesn't work, that will just list ALL the user emails and not depending on their meta data.
Anyone that can help me?
PS. I've just started to code so please be nice to me :)
function get_user_by_meta_data ($meta_key, $meta_value) {
$args = array(
'meta_key' => $meta_key,
'meta_value' => $meta_value
);
// The Query
$user_query = new WP_User_Query( $args );
// The Results
$users = $user_query->get_results();
$result = array();
// User Loop
foreach ( $users as $user ) {
$result[] = $user->user_email;
}
return "<span>" . implode( ', ', $result ) . "</span>";
}