Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Created August 11, 2020 22:39
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 damiencarbery/6897e7e1eddcb5416996e233ea4ef4d2 to your computer and use it in GitHub Desktop.
Save damiencarbery/6897e7e1eddcb5416996e233ea4ef4d2 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Change post order by category
Plugin URI: https://www.damiencarbery.com
Description: Order Blog category by date, rest alphabetically.
Author: Damien Carbery
Version: 0.1
*/
// Change the post order to ascending by title for all categories except the 'blog' category.
add_action( 'pre_get_posts', 'dcwd_change_post_order_by_category' );
function dcwd_change_post_order_by_category( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( ! is_category( 'blog' ) ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'asc' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment