From e4bb2ba69200c65dda9ae780924545f7ceba8c05 Mon Sep 17 00:00:00 2001 From: Faishal Saiyed Date: Mon, 2 Feb 2015 18:58:13 +0530 Subject: [PATCH] Fix custom post type archive template issue to deal with the shadow post types for archive templates, ensuring they use the right template. --- class-post-public.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/class-post-public.php b/class-post-public.php index 34f1efd..8e331e8 100644 --- a/class-post-public.php +++ b/class-post-public.php @@ -108,6 +108,7 @@ public function __construct() { $this->add_filter( 'post_type_link', null, null, 3 ); $this->add_filter( 'get_sample_permalink', null, null, 5 ); $this->add_filter( 'single_template' ); + $this->add_filter( 'archive_template' ); $this->add_filter( 'the_posts', null, null, 2 ); $this->add_filter( 'bbl_translated_taxonomy', null, null, 2 ); $this->add_filter( 'admin_body_class' ); @@ -945,6 +946,34 @@ public function single_template( $template ) { return $template; } + /** + * Hooks the WP filter archive_template to deal with the shadow post + * types for archive templates, ensuring they use the + * right template. + * + * @param string $template Path to a template file + * @return Path to a template file + **/ + function archive_template( $template ) { + if ( bbl_is_default_lang() ) { + return $template; + } + if ( $this->no_recursion ) { + return $template; + } + $this->no_recursion = true; + $original_post_type = reset( array_filter( (array) get_query_var( 'post_type' ) ) ); + $post_types = $this->get_base_post_type( $original_post_type ); + $templates = array(); + $templates[ ] = "archive-{$post_types}.php"; + $templates[ ] = "archive-{$original_post_type}.php"; + $templates[ ] = 'archive.php'; + $template = get_query_template( 'archive', $templates ); + $this->no_recursion = false; + + return $template; + } + /** * Hooks the bbl_sync_meta_key filter from this class which checks * if a meta_key should be synced. If we return false, it won't be.