So I have a function that creates a mailing list of all users that have a specific user meta key checked using shortcode attributes. The function works well but I can't figure out how to display the LABEL instead of the meta key ($args['meta_label'] won't do it and $args['meta_value'] will only show "1" since the field is a true/false button). I have been using ACF when creating the user meta fields.
function mailing_list_shortcode ($atts) {
$args = shortcode_atts(array(
'meta_key' => '',
'meta_value' => '',
), $atts );
// The Query
$user_query = new WP_User_Query( $args );
// The Results
$users = $user_query->get_results();
$result = array();
// We have some users that match the conditions
if ( ! empty($users) ) {
// User Loop
foreach ( $users as $user ) {
$result[] = $user->user_email;
}
return "<a href=\"mailto:" . implode(',', $result) . "\">" . $args['meta_key'] . "</a>";
}
}
add_shortcode( 'mailing_list', 'mailing_list_shortcode');
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744715977a4589619.html
评论列表(0条)