Created
October 18, 2016 18:37
-
-
Save joelworsham/997cc6b87fc92831bb53f1528b493ab5 to your computer and use it in GitHub Desktop.
LearnDash Gradebook re-order grades example
This file contains hidden or 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 | |
function my_modify_gradebook_type_posts( $wp_query ) { | |
// Make sure it's the proper query | |
if ( $wp_query->is_main_query() || | |
$wp_query->get('post_type') != array( 'sfwd-assignment', 'sfwd-quiz' ) || | |
! $wp_query->get('tax_query') | |
) { | |
return; | |
} | |
$tax_query = $wp_query->get('tax_query'); | |
// Check even further it's the proper query | |
if ( ! isset( $tax_query[0] ) || | |
$tax_query[0]['taxonomy'] != 'gradebook-type' | |
) { | |
return; | |
} | |
$type_id = $tax_query[0]['terms']; | |
// If we know the Type term id or name or something, and we want to limit to | |
// that, we can add a conditional here. | |
// Conditional by term id | |
// if ( $type_id != '54' ) { | |
// return; | |
// } | |
// Conditional by term name | |
// $type = get_term( $type_id ); | |
// if ( $type->name != 'Term Name') { | |
// return; | |
// } | |
// Finally decide we want to add our orderby params. This can be whatever, below | |
// is only one example. | |
$wp_query->set( 'orderby', 'title' ); | |
$wp_query->set( 'order', 'ASC' ); | |
} | |
add_filter( 'pre_get_posts', 'my_modify_gradebook_type_posts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment