admin管理员组文章数量:1124409
I use WordPress with Polylang PRO and ACF PRO plugins.
Using ACF PRO I've created CPT with post_type 'aktualnosc', with rewrite slug 'aktualnosci' (same slug as page name (with posts list)).
I also use Polylang PRO to translate CPT slugs into other languages.
To fix CPT pagination I use this PHP function.
add_action( 'init', function () {
$post_types = get_post_types( '', 'objects' );
foreach ( $post_types as $post_type ) {
if ( $post_type->rewrite ) {
$default_slug = $post_type->rewrite['slug'];
if ( function_exists( 'pll_languages_list' ) ) {
$languages = pll_languages_list();
foreach ( $languages as $lang ) {
$translated_slug = pll_translate_string( $default_slug, $lang );
add_rewrite_rule(
'^' . $translated_slug . '/page/(\d+)/?$',
'index.php?pagename=' . $translated_slug . '&paged=$matches[1]',
'top'
);
}
} else {
add_rewrite_rule(
'^' . $default_slug . '/page/(\d+)/?$',
'index.php?pagename=' . $default_slug . '&paged=$matches[1]',
'top'
);
}
}
}
} );
It works on default CPT slug, but if I click page 2 in pagination on the other language than default CPT slug it causes 'Error 404'.
I've stuck. Have you encountered such a problem and solved it?
版权声明:本文标题:url rewriting - WordPress pagination error when using ACF CPT rewrite slug & Polylang CPT slug translation 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736625427a1945664.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论