Created
May 13, 2015 23:36
-
-
Save srikat/ec392a554f78fb27f8b3 to your computer and use it in GitHub Desktop.
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/
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
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