Created
May 28, 2020 09:29
-
-
Save kurudrive/92ce3be9024691c0bc70d54511fb9118 to your computer and use it in GitHub Desktop.
カテゴリーアーカイブやタグアーカイブで表示順をランダムにする
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
function my_change_query( $query ) { | |
// 管理画面では何もしない | |
if ( is_admin() || ! $query->is_main_query() ) { | |
return; | |
} | |
// カテゴリーページでランダムにする | |
if ( $query->is_category() ) { | |
$query->set( 'orderby', 'rand' ); | |
return; | |
} | |
// タグページでランダムにする | |
if ( $query->is_tag() ) { | |
$query->set( 'orderby', 'rand' ); | |
return; | |
} | |
} | |
add_action( 'pre_get_posts', 'my_change_query' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment