Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.