Last active
June 1, 2020 20:50
-
-
Save luizlopescom/46a8101a904e58cd862c263c7bad489f to your computer and use it in GitHub Desktop.
WordPress Archive.php - change sort order
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
// Display Fornecedores & Produtos in ASC order by title | |
function my_change_sort_order($query){ | |
if(is_archive()): //If you wanted it for the archive of a custom post type use: is_post_type_archive( $post_type ) | |
//if (is_post_type_archive( 'fornecedores' ) | is_post_type_archive( 'produtos' ) ): | |
//Set the order ASC or DESC | |
$query->set( 'order', 'ASC' ); | |
//Set the orderby | |
$query->set( 'orderby', 'title' ); | |
endif; | |
}; | |
add_action( 'pre_get_posts', 'my_change_sort_order'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment