availability:

WPML Version: 3.2.3

description:
  • Gets the post type slug translation in a specific language.
  • The translation value is saved in WPML->Translation Management->Multilingual Content Setup->Custom posts.
type:
filter
category:
Retrieving Localized Content
parameters:
$translated_slug = apply_filters( 'wpml_get_translated_slug', string $slug, string $post_type, string $language_code );
$slug
(string) (Required) The value is set in the rewrite argument of the register_post_type function.
$post_type
(string) (Required) The first parameter value of the register_post_type function.
$language_code
(string) (Optional) Return the translation in this language. Default is NULL which returns the current language.
hook example usage:

Register a book post type with the custom slug my-book.

In WPML->Translation Management->Multilingual Content Setup->Custom posts, translate the custom slug into Spanish with the value mi-libro.

Use the wpml_get_translated_slug hook to get the Spanish translation of this custom slug, which is mi-libro.

The example for wpml_get_translated_slug.
The example for wpml_get_translated_slug.

Example

// Register a "book" post type with the custom slug "my-book"
add_action( 'init', 'register_book_init' );

function register_book_init() {
	$labels = array(
		'name'               => _x( 'Books', 'post type general name', 'your-plugin-textdomain' ),
		'singular_name'      => _x( 'Book', 'post type singular name', 'your-plugin-textdomain' )
	);

	$args = array(
		'labels'             => $labels,
		'public'             => true,
		'publicly_queryable' => true,
		'show_ui'            => true,
		'show_in_menu'       => true,
		'rewrite'            => array( 'slug' => 'my-book' ),
	);

	register_post_type( 'book', $args ); 
}

// Get the Spanish translation of the post type slug "my-book" 
// This value is saved in WPML->Translation Management->Multilingual Content Setup->Custom posts
$translated_slug = apply_filters( 'wpml_get_translated_slug', 'my-book', 'book' ,'es' );
// Return "mi-libro"
echo $translated_slug;