I have these two functions.
The difference is that one is filtering custom taxonomy (is_tax) and the other is filtering generic WordPress tags (is_tag).
The work as I'd like them to be it seems that the code is being duplicated.
This is Taxonomy:
add_action( 'pre_get_posts', 'sort_conference_by_date_tax' );
function sort_conference_by_date_tax( $query ) {
if ( $query->is_main_query() && !is_admin() ) {
if ( $query->is_tax() ) {
$query->set('orderby', 'meta_value');
$query->set('meta_key', 'start_date');
$query->set('order', 'DESC');
}
}
}
This is for Tags (Standard WordPress)
add_action( 'pre_get_posts', 'sort_conference_by_date_tag' );
function sort_conference_by_date_tag( $query ) {
if ( $query->is_main_query() && !is_admin() ) {
if ( $query->is_tag() ) {
$query->set('orderby', 'meta_value');
$query->set('meta_key', 'start_date');
$query->set('order', 'DESC');
}
}
}
I thought an array would work like this:
if ( $query->(array(('tag', 'tax'))) {
return 0;
}
But it didn't seem to work for me...
I guess I am only doing something that would save a fraction of a second by merging these functions so if it can't be done prob best to just leave it alone right?
Thanks