設定
設定特定の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
);