Skip to content

Instantly share code, notes, and snippets.

@srikat
Created May 13, 2015
Embed
What would you like to do?
Displaying entries on a CPT archive page in random order in WordPress. https://sridharkatakam.com/displaying-entries-on-a-cpt-archive-page-in-random-order-in-wordpress/
add_action( 'pre_get_posts', 'sk_portfolio_archive_random' );
/**
* Set Random order for entries in Portfolio archive page
*
* @author Bill Erickson
* @author Sridhar Katakam
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @param object $query data
*
*/
function sk_portfolio_archive_random( $query ) {
if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'portfolio' ) ) {
$query->set( 'orderby', 'rand' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment