Created
August 11, 2020 22:39
-
-
Save damiencarbery/6897e7e1eddcb5416996e233ea4ef4d2 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
<?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