Skip to content

Instantly share code, notes, and snippets.

@luizlopescom
Last active June 1, 2020 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luizlopescom/46a8101a904e58cd862c263c7bad489f to your computer and use it in GitHub Desktop.
Save luizlopescom/46a8101a904e58cd862c263c7bad489f to your computer and use it in GitHub Desktop.
WordPress Archive.php - change sort order
// 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