Last active
December 10, 2018 14:46
-
-
Save cabrerahector/f8d4dc493b121ddad047faece7919acc to your computer and use it in GitHub Desktop.
Get Random Posts with Recently
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.