It’s a small coding mistake..
It’s not displaying anything because when there are results, the end output is always a </ul>
because you’re always overwriting the $results
and not appending output to the variable:
$results="<ul>";
foreach ($users as $user){
$results="<li>" . $user->display_name . '</li>';
}
$results="</ul>";
So the proper code is:
$results="<ul>";
foreach ($users as $user){
$results .= '<li>' . $user->display_name . '</li>';
}
$results .= '</ul>';
And there’s no need to call wp_reset_postdata()
because in your code, there’s no call to any functions which modifies the global $post
object/data.
Related Posts:
- Display current user metadata on WordPress page
- How Can I Display the Last Modified Date for User Profiles on WordPress?
- Add another role to a user when they click a button?
- Get author meta of all writers
- How to manually fix the WordPress gallery code using PHP in functions.php?
- Shortcode putting html such as
- Counting number of posts in a category and its sub categories and displaying result using shortcode
- Calling a method from functions.php on a click of a button
- Shortcode created to check language not works
- Add/echo div with Analytics-Code to function in functions.php
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- How can I default to all WordPress roles when parameter is not included in shortcode?
- WordPress menu deletes when trying to add a hook
- Wrap each shortcode in array to div
- Recent post display using shortcode
- Nested shortCode functions in the functions.php file
- Making Quote Plugin more efficient
- Shortcode content output but not in correct place
- is_page “range” for if statement?
- PHP code inside shortcodes
- Shortcode content filter?
- How do I display a user’s previous orders as a select box option on a product?
- Trigger popup in a php if/else statement
- create shortcode to list users with specific meta key value
- How to output a PHP file values by shortcode?
- Showing content from one page on another
- Get value from shortcode to do something
- How to check if a meta value has already been assigned to any user?
- function to assign user role based on a field from usermeta
- Custom shortcode outputs plain text instead of HTML at top of post
- How to abort saving data in save_extra_profile_fields function WordPress?
- Pass php dynamic variable to shortcode
- Update user profile information from functions.php
- How to Reference/Echo Variable from Another PHP Function
- Remove echo from shortcode
- Shortcode with PHP issue “Undefined index”
- Shortcode from a function not working
- Display Data in Table from External Database in WP using Shortcodes
- Read array in php?
- Is it possible to return content, and then also continue to do other things?
- ::before on open/close function [closed]
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Creating WordPress Shortcode with Variable
- Shortcode to find and replace URL
- Countdown to date function?
- calling a custom field value inside functions.php
- How to keep the capability of users and disable Gutenberg editor in WordPress?
- List all blogs, but exclude the main site
- Shortcode to embed Edit Account form not working
- If Array Values Match Another Array’s Values, Then
- Cant display an image via PHP in wordpress
- How to return a string that has a jQuery and Ajax inside in a shortcode?
- Query for user roles
- Create special button on WP Tiny MCE Posts Editor for Shortcodes
- AJAX function not working [closed]
- Uses for function: wp_update_user
- Execute PHP code only with specific user role
- Updating Metadata with Shortcode
- Display logged in user name and lastname on page
- How to Add a cutsom slug to my custom author role
- Create shortcode for metabox gallery
- Allow a user or role to view drafts and previews, but not other admin privileges?
- Display Visual Composer shortcode if a post belongs in specific categories
- How to add and subtract user meta values after post meta update
- How do I reopen the (Popup Maker) after entering the correct password for a password protected page?
- WP custom posts: filter results to custom taxonomy tag that corresponds to user meta field
- Hide payment method based on user role AND minimum cart value
- How can I prevent a shortcode div from extending beyond its boundaries?
- Gravity Forms: How to add PHP function to confirmation conditional shortcode?
- wpdb->query returns different value to phpMyAdmin
- Display a custom name when the user has no name settle in his account
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Edit a function to take different actions based on user role
- Reload page with a different shortcode when a user selects from a dropdown
- Get user by meta data key and velue
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- Offset with ajax load more posts duplicates
- Get posts by id using shortcode
- Store custom field’s multiple values in one user meta key
- Get field in readable word
- Shortcode’s output to use as other shortcode’s parameter
- Open/closed function [closed]
- Need to Echo A Url path to show on a wordpress page
- Wrapping shortcode content in a span or link
- Need help with PHP functions
- Private messaging – Getting and displaying the avatar/url of a message recipient
- Allow BBPress participant role to trash topics
- Limit the number of successful logins
- How to have Function of a plugin using global vars into a shortcode?
- Overwriting a Shortcode
- Shortcoding with Divs
- Whats wrong with my code? Need To add String to shortcode? [closed]
- My title is showing after the shortcode
- A next page function with shortcode?
- Shortcode to include PHP file, pass various parameters to include?
- A better way to write this php function
- WP Custom tables query
- Display terms on product page with shotrcode
- How call WordPress shortcode inside function file
- Custom Admin Menu Report for Specific User ID