Created
March 6, 2015 18:25
-
-
Save codehooligans/775abfb24794842c8142 to your computer and use it in GitHub Desktop.
To correct the post_type 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
add_action( 'pre_get_posts', 'attraction_pre_get_post', 1 ); | |
function attraction_pre_get_post( $query ) { | |
if ( $query->is_main_query() ) { | |
if ( ( $query->is_archive ) && ( $query->is_tax ) ) { | |
if ( ( !isset( $query->post_type ) ) || ( empty( $query->post_type ) ) ) { | |
$queried_object = get_queried_object(); | |
if ( !isset($queried_object->taxonomy ) ) | |
return; | |
if ( ( $queried_object->taxonomy != 'attraction-country' ) && ( $queried_object->taxonomy != 'accommodation-country' ) ) | |
return; | |
global $wp_taxonomies; | |
if ( !isset( $wp_taxonomies[$queried_object->taxonomy] ) ) return; | |
if ( !isset( $wp_taxonomies[$queried_object->taxonomy]->object_type ) ) return; | |
$query->set( 'post_type', $wp_taxonomies[$queried_object->taxonomy]->object_type ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment