The Codex lists rand
as the orderby
string, not RAND
. I suspect that either works but I haven’t checked. But that isn’t how I’d do this. I’d lean toward something like…
$current_category_ID = getCurrentCatID();
$current_cat_id = $current_category_ID;
$author_array = array();
$args = array(
'numberposts' => -1,
'cat' => $current_cat_id
);
$cat_posts = get_posts($args);
foreach ($cat_posts as $cat_post) :
if (!in_array($cat_post->post_author,$author_array)) {
$author_array[] = $cat_post->post_author;
}
endforeach;
shuffle($author_array); // randomize
Database ORDER BY
isn’t terribly efficient. ORDER BY RAND
is especially inefficient. That code does the sorting in PHP on a smaller array, so it should perform better.
Related Posts:
- wordpress plugin that show my reputation (points) in any stackexchange project in my wordpress blogs
- Where do I put the code snippets I found here or somewhere else on the web?
- Publish author posts only with editor approval?
- Customizing subject in comment notification e-mails
- Common functionality between my own plugins
- How to Loop Plugin Option Field Set?
- How to handel multiple checkbox field in the admin settings page with Settings API
- Why does including a file in theme’s functions.php not work?
- wp_insert_user – how to send verification email before logging in
- Editor access to plugin settings
- Saving Plugin settings to the database
- Set a User as Author of all ‘New Posts’ posted
- Shortcode display outside the div
- Change destination author link
- Execute a function using ajax
- Add Top-Level Menu that opens URL
- Use functionality of 2 wordpress plugins
- What is the function to get plugin base url in multisite?
- Extend Elementor Archive Posts widget with a custom skin in order to show multiple badges
- HELP: Integrating WP with raw PHP code once published button is hit
- Override the core function locate_template
- Can wp_script_is used in pluginA check if a script is being enqueued/registered from pluginB?
- I would like to use create a function in my custom plugin to tell WP to use a different header
- Placement of Code in Plugin for hooking `save_post`
- Scope for PHP Variables Assigned in functions.php or a plugin
- How to get variables from fucntion.php to my plugin files
- Avoiding Duplicate function names in Post Loop (WP_Footer script)
- How to add class in plugin only for network site?
- plugin development: problem with functions
- wordpress plugin is not activating from widget
- Edit Yoast SEO breadcrumbs output [closed]
- Display post lists in 2nd paragraph
- Using a post-signup hook to get user details
- creating html reusable blocks via shortcodes
- Modifying Author Link to add Author Meta in URL
- How to set add question capability for author role in wp pro quiz plugin
- Conditional attributes and logic per product category
- WordPress get_avatar function not correct working
- Which file of wordpress manage plugins functionalities?
- Difference and examples of esc_attr__() and esc_attr_e()
- Redirect to another page using contact form 7? [closed]
- List the authors that have written posts in a category
- Check if variable is set in filter
- execute function after one completed
- WordPress checkbox and Illegal string offset
- plugins_url() works everywhere but wp_reqister_script()
- Shortcode Attributes to Return different $_POST
- Plugin onclick button activate other plugin
- strange shortcode error: does shortcodes requires any dependency?
- How to access OOP plugin function inside themes or other plugin
- My widget won’t update its values when save is clicked
- how can authors to define custom pages?
- How can i listing current category and Featured Category post list?
- More gentle way to hook WordPress custom url
- How to add custom function to pluggable.php
- auto activate plugin when theme is active
- Checkbox show / hide output result
- co-authors plugin – inline listing
- How to keep plugin (media-sync) running even the tab is closed?
- Where do I put the code snippets I found here or somewhere else on the web?
- How to upload large media file in chunks, without any plugin?
- Allow a particular user to access a particular plugin?
- How to copy the all WordPress media items to another custom plugin folder?
- Cookie value changes back to previous value after changing
- Is there any way to sync Facebook Comments and with comments on WordPress website?
- Fatal error “Call to undefined function is_plugin_active” each time the plugin is activated
- function post to trash problem
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- The function called on the wp head hook becomes null
- adding dynamic/multiple slug values in ‘option_none_value’
- Changing author slug for a custom role without using plugin
- Is admin section completely customizable in terms of styling?
- WordPress environment not loading properly
- WordPress Add advertising ads befor and after content with periority [closed]
- plugin not hooking to my custom hook
- Populate select option with JSON file
- Can plugin automatically update if i hide the update notification?
- Displaying friend’s posts only
- Why isn’t my plugin seeing other classes?
- how to create table during plugin installation in side a class
- Hook into install email
- How to add submenu to WordPress plugin in the same Directory of main Plugin?
- WordPress plugin options need to delete after deactivate & uninstall
- Saving an array to get_options
- Saving plugin data returns “You do not have sufficient permissions to access this page.”
- How to Overwrite validate_plugin function
- How to add a handler for a button in plugin?
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- Custom Function for SEO by Yoast plugin
- Doing action based on input from options menu
- Call current post parameters inside a plugin
- How to list posts that appear in two categories
- Pass strings to plugin function [closed]
- How use Dynamic hyperlink on each wordpress post?
- Send email notification when meet the condition
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- Gravity Forms and Gravity View Permissions
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- wp_enqueue_script doesn’t load JS in plugin
- Shortcode cannot parse attributes within double quotes. ” is becoming ” breaking my shortcode