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
- Placing raw HTML inside a WordPress shortcode
- 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
- How to display posts by current user in a drop down
- 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
- 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
- Execute function only for specific user roles
- 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
- Why is the current page loaded in the pop-up window and not the specified one?
- 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?
- Block error message in foreach loop when looping through ACF field
- Include User ID in iFrame URL
- 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?
- PHP multiple forms, same page, isset($_POST[]) not working?
- Gravity Forms: How to add PHP function to confirmation conditional shortcode?
- wpdb->query returns different value to phpMyAdmin
- shortcodes, custom php and their errors
- 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
- Where do I implement this display of User Meta Data, and how to put it in a table?
- 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
- Show Login Errors In WordPress/Elementor (Code “works”, but breaks site)
- Custom Admin Menu Report for Specific User ID
- Calling a function via a shortcode in javascript
- Adding a css class to the gallery
- Strip and print only the numbers found in current’s post excerpt (even if they are without space)
- Woocomerce custom add to cart button edit functionality [closed]
- Hide ID for WordPress User Role Subscriber