Created
April 27, 2016 16:11
-
-
Save stephanieleary/c725ea4620e9d434e71927ab41879f38 to your computer and use it in GitHub Desktop.
infer post type when query var is not set
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 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