Created
August 16, 2021 13:17
-
-
Save dcooney/41547b97f42e1995ecd7dcc7a79554c2 to your computer and use it in GitHub Desktop.
ALM Filters - Default Archive Query
This file contains 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_alm_filter_query_args( $args ){ | |
// Get the archive query object. | |
$queried_obj = get_queried_object(); | |
// Confirm archive and query object is available. | |
if ( is_archive() && $queried_obj && isset( $queried_obj->taxonomy ) ) { | |
// The default taxonomy query. | |
$default_tax_query = array( | |
'taxonomy' => $queried_obj->taxonomy, | |
'terms' => $queried_obj->slug, | |
'field' => 'slug', | |
'operator' => 'IN' | |
); | |
if ( isset( $args[ 'tax_query' ] ) && $args[ 'tax_query' ] ) { | |
// Has tax query: Append to default to existing. | |
$args['tax_query'][] = $default_tax_query; | |
} else { | |
// No tax query currently exists. | |
$args['tax_query'] = array ( $default_tax_query ); | |
} | |
} | |
return $args; | |
} | |
add_filter( 'alm_query_args_category', 'my_alm_filter_query_args'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment