Skip to content

Instantly share code, notes, and snippets.

@cabrerahector
Last active December 10, 2018 14:46
Show Gist options
  • Save cabrerahector/f8d4dc493b121ddad047faece7919acc to your computer and use it in GitHub Desktop.
Save cabrerahector/f8d4dc493b121ddad047faece7919acc to your computer and use it in GitHub Desktop.
Get Random Posts with Recently
<?php
// https://github.com/cabrerahector/recently/
/**
* Have Recently return random posts
* for widget instance ID 'recently-2'
*
* @param array $args The args passed to WP_Query.
* @param string $widget_id The ID of the current widget instance.
* @return array
*/
function recently_get_random_posts( $args, $widget_id ){
if ( 'recently-2' == $widget_id )
$args['orderby'] = 'rand';
return $args;
}
add_filter( 'recently_pre_get_posts', 'recently_get_random_posts', 10, 2 );
@cabrerahector
Copy link
Author

cabrerahector commented Dec 8, 2018

Replace the string recently-2 with the actual instance ID of the widget you want to manipulate. You can use Get Widget ID to easily identify the ID of each widget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment