Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom post type archive template issue #205

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions class-post-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -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.
Expand Down