Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Forked from robneu/reverse-post-order.php
Last active December 19, 2015 10:29
Show Gist options
  • Save GaryJones/5941070 to your computer and use it in GitHub Desktop.
Save GaryJones/5941070 to your computer and use it in GitHub Desktop.
Completely untested!
<?php
add_action( 'pre_get_posts', 'prefix_reverse_post_order' );
/**
* Reverse Post Order for Post Archives on the Genesis Framework
*
* @author FAT Media
* @link http://youneedfat.com/reverse-post-order-genesis-framework/
* @param object $query data
*
*/
function prefix_reverse_post_order( $query ) {
if ( is_admin() )
return;
// Make sure we only change the query for post archives
if ( $query->is_main_query() && ( is_home() || is_post_type_archive( 'post' ) ) )
$query->set( 'order', 'ASC' );
// This will affect each and every usage of the Blog page template!
if ( is_page_template( 'page_blog.php' ) )
add_filter( 'genesis_custom_loop_args', 'prefix_filter_genesis_query_args_field' );
}
/**
* Filter custom loop args.
*
* Since this is only kicked in when the page template is the Blog template, we know we're not affecting every other
* custom loop.
*
* @param array $args All of the custom loop arguments.
*
* @return array
*/
function prefix_filter_genesis_query_args_field( array $args ) {
$args['order'] = 'ASC';
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment