Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
infer post type when query var is not set
<?php
function berkeley_find_post_type() {
$type = get_query_var( 'post_type' );
if ( ( !isset( $type ) || empty( $type ) ) && is_tax() ) {
// we're on a term archive, where post type might not be set but can be inferred from taxonomy's object_type
$current_term = get_queried_object();
$tax_obj = get_taxonomy( $current_term->taxonomy );
if ( count( $tax_obj->object_type ) == 1 )
$type = $tax_obj->object_type[0];
}
return $type;
}
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.