我有一个函数,用于列出特定角色中与特定元键值匹配的用户。当我直接在页面上使用它时,它会起作用---
<?php
$bmail = $current_user->user_email;
$user_query = new WP_User_Query( array( \'meta_key\' => \'broker_email\', \'meta_value\' => $bmail, \'fields\' => \'all\' ) );
$users = $user_query->get_results();
if (!empty($users)) {
echo \'<ul>\';
foreach ($users as $user){
echo \'<li>\' . $user->display_name . \'</li>\';
}
echo \'</ul>\';
} else {
echo \'No users found\';
};
?>
但是当我尝试创建一个快捷代码时--function thebroker_agents() {
global $current_user;
$bmail = $current_user->user_email;
$user_query = new WP_User_Query( array( \'meta_key\' => \'broker_email\', \'meta_value\' => $bmail, \'fields\' => \'all\' ) );
$users = $user_query->get_results();
if (!empty($users)) {
echo \'<ul>\';
foreach ($users as $user){
echo \'<li>\' . $user->display_name . \'</li>\';
}
echo \'</ul>\';
} else {
echo \'No users found\';
}
// Adds the above function as as shortcode
add_shortcode( \'your_agents\', \'thebroker_agents\' );
像这样在同一页上打电话--<?php echo do_shortcode(\'[your_agents]\'); ?>
除了回显文本-“[您的\\u代理]”,它什么都不做我的shortcode函数有什么错?