設定特定のCPTのスラッグのみを翻訳する
特定のCPTのスラッグのみを翻訳する
このプラグインは、設定画面で投稿スラッグを翻訳するオプションを提供しており、すべてのカスタム投稿タイプに適用されます。

特定のカスタム投稿タイプのみスラッグを翻訳し、他のものは翻訳しない場合は、フック gatompl:query_variables を使用して実現できます:
add_filter(
'gatompl:query_variables',
/**
* @param array<string, mixed> $variables The variables to pass to the query.
* @return array<string, mixed> The variables to pass to the query.
*/
function (
array $variables,
string $querySlug
): array {
if ($querySlug === 'translate-customposts') {
// Define the CPTs for which you want to translate the slug
$translateSlugForCTPs = [
'my-custom-post-type',
];
/** @var string */
$customPostType = $variables['customPostType'];
$variables['updateSlug'] = in_array($customPostType, $translateSlugForCTPs);
}
return $variables;
},
10,
2
);