Skip to content

Instantly share code, notes, and snippets.

@codehooligans
Created March 6, 2015 18:25
Show Gist options
  • Save codehooligans/775abfb24794842c8142 to your computer and use it in GitHub Desktop.
Save codehooligans/775abfb24794842c8142 to your computer and use it in GitHub Desktop.
To correct the post_type query
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