Skip to content

TypeWithArchive rewrite-rule should not be done if not archive page set #87

@kuuak

Description

@kuuak

If no page_for_xxx is set, the archive_paged_rewrite function should not alter the rewrite rules as it leads to "catch all" rewrites.

function archive_paged_rewrite($rules) {
$cpt_name = $this->getName();
if($cpt_name === 'post') return $rules; // Bail early if it's a post (as the pagination rules already exist)
$rule = array_filter($rules, function($regex) {
return strpos( $regex, '([^/]+)/page' ) > -1;
}, ARRAY_FILTER_USE_KEY);
if ( empty($rule) ) return $rules;
$new_regex = str_replace( '([^/]+)/page/', 'page/', array_keys($rule)[0] );
$new_regex = str_replace( '?:', '', $new_regex );
$archive_link = $this->get_archive_page_url();
$new_rules = array_merge([
$new_regex => 'index.php?pagename='.str_replace('/','',$archive_link).'&paged=$matches[1]',
], $rules);
return $new_rules;
}

Image

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions