use standard template for tax archive when tax is shared with post types

This commit is contained in:
Leo Germani 2019-01-25 16:24:59 -02:00
parent 3894a90a49
commit 9bbdc98ae7
2 changed files with 40 additions and 3 deletions

View File

@ -359,6 +359,18 @@ class Taxonomies extends Repository {
return $prefix . $id;
}
public function get_id_by_db_identifier( $db_identifier ) {
$prefix = \Tainacan\Entities\Taxonomy::$db_identifier_prefix;
//$sufix = \Tainacan\Entities\Taxonomy::$db_identifier_sufix;
$id = str_replace( $prefix, '', $db_identifier );
//$id = str_replace( $sufix, '', $id );
if ( is_numeric( $id ) ) {
return (int) $id;
}
return false;
}
/**
* Check if a term already exists
*

View File

@ -208,9 +208,22 @@ class Theme_Helper {
$term = get_queried_object();
if ($term instanceof \WP_Term && $this->is_term_a_tainacan_term($term)) {
// TODO: Why post_type = any does not work?
// ANSWER because post types are registered with exclude_from_search. Should we change it?
$wp_query->set( 'post_type', \Tainacan\Repositories\Repository::get_collections_db_identifiers() );
$tax_id = \Tainacan\Repositories\Taxonomies::get_instance()->get_id_by_db_identifier($term->taxonomy);
$tax = \Tainacan\Repositories\Taxonomies::get_instance()->fetch($tax_id);
if ( $tax ) {
$post_types = $tax->get_enabled_post_types();
// TODO: Why post_type = any does not work?
// ANSWER because post types are registered with exclude_from_search. Should we change it?
// TODO adding all post types to the list is something we need to discuss
$post_types = array_merge($post_types, \Tainacan\Repositories\Repository::get_collections_db_identifiers());
$wp_query->set( 'post_type', $post_types);
}
}
}
@ -285,6 +298,18 @@ class Theme_Helper {
$term = get_queried_object();
if ( isset($term->taxonomy) && $this->is_taxonomy_a_tainacan_tax($term->taxonomy)) {
$tax_id = \Tainacan\Repositories\Taxonomies::get_instance()->get_id_by_db_identifier($term->taxonomy);
$tax = \Tainacan\Repositories\Taxonomies::get_instance()->fetch($tax_id);
if ( $tax ) {
$post_types = $tax->get_enabled_post_types();
if (sizeof($post_types)) {
// if taxonomy is enabled for other post types, we disable
// custom template ans use default list
// TODO: This needs discussion
return $templates;
}
}
$last_template = array_pop($templates);