Skip to content

Instantly share code, notes, and snippets.

@robincornett
Created May 24, 2014 15:48
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 robincornett/ea4f46da7e47e3ee0266 to your computer and use it in GitHub Desktop.
Save robincornett/ea4f46da7e47e3ee0266 to your computer and use it in GitHub Desktop.
Example function of how to set the order of posts for an archive or taxonomy--specifically for a custom post type, but can be used anywhere posts are listed, such as a specific category/taxonomy.
<?php
/*
* This function is part of Simple Staff for Genesis. Extracted for educational purposes. Could be used also
* in a theme's functions.php file, if you're not working with a plugin. Do not include the opening tag.
*/
add_action( 'pre_get_posts', 'simple_staff_order', 9999 );
function simple_staff_order( $query ) {
if ( $query->is_main_query() && ( is_post_type_archive( 'staff' ) || is_tax( 'department' ) ) ) {
$query->set( 'orderby', 'menu_order' );
$query->set( 'order', 'ASC' );
$query->set( 'posts_per_page', -1 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment