Changing Order of Posts for Taxonomy Archive in Genesis Loop

Need to change the sort direction or filter output based on Taxonomy for a Genesis theme? This method will work for you.

for ordering the pods in order by a custom field (in this case a date). I added this to my theme functions.php (not this isa Genesis theme):

/**
* Sort all of the cases being displayed by the 'court_date' custom field.
*
* We're hooking to `genesis_before_loop`, and modifying the query arguments before anything is output.
*
* @since 1.0.0
*/
function madden_sort_cases_by_court_date() {

    // If we're not in one of these case-related taxonomies, we need to bail out.
    if( ! is_tax( [ 'court', 'lawyer', 'procedural_expertise', 'substantive-expertise' ] ) ) {
        return;
    }

    // Bring in $wp_query
    global $query_string;

    // Set our additional query arguments.
    $args = [
        'order' => 'DESC',
        'orderby' => 'meta_value',
        'meta_key' => 'court_date',
    ]

    // Merge in our arguments using `wp_parse_args`.
    query_posts( wp_parse_args( $query_string, $args ) );

}

You can also use this method within a taxonomy.php  or archive.php  to handle taxonomy archive sorting.

Contributed by Tara Claeys

Questions