 panagiotisE
|
Hi,
I found the code below for what I need and works fine. But I need to be applicable only to custom post type "event".
add_filter( 'icl_job_elements', 'filter_title', 10, 2 );
function filter_title( $fields, $post_id )
{
foreach ($fields as $field => $value) {
if ($value->field_type == "title") {
$value->field_translate = 0;
$value->field_data_translated = $value->field_data;
}
}
return $fields;
}
|
 Bruno Kos
WPML Supporter since 12/2018
Languages:
English (English )
German (Deutsch )
French (Français )
Timezone:
Europe/Zagreb (GMT+02:00)
|
Hi,
Thank you for contacting WPML support!
To make the code applicable only to a custom post type "event", you need to check the post type of the post being processed before applying the changes. This can be achieved by getting the post type of the `$post_id` and then applying your modifications only if the post type is "event". You can use `get_post_type()` function for this purpose.
Here's how you can modify your function - I haven't tested this though.
add_filter( 'icl_job_elements', 'filter_title_for_events_only', 10, 2 );
function filter_title_for_events_only( $fields, $post_id ) {
// Check if the post type is 'event'
if ( 'event' === get_post_type( $post_id ) ) {
foreach ( $fields as $field => $value ) {
if ( $value->field_type == "title" ) {
$value->field_translate = 0;
$value->field_data_translated = $value->field_data;
}
}
}
return $fields;
}
This modified version of your function first checks if the post type of the current post (`$post_id`) is `event`. If it is, it proceeds with the loop to apply your modifications to the title field. If the post type is not `event`, it simply returns the fields without any changes. This way, your modifications are applied only to posts of type "event".
Regards,
Bruno Kos
|
 panagiotisE
|
It works perfect! Thank you!
One last question... "event" post type is used just for data entry, it has not public url. So is it possible to remove slug too, as the title? I tried the below but it doesn't work.
if ( $value->field_type == "title" || $value->field_type == "url" || $value->field_type == "slug" )
|
 Bruno Kos
WPML Supporter since 12/2018
Languages:
English (English )
German (Deutsch )
French (Français )
Timezone:
Europe/Zagreb (GMT+02:00)
|
To remove slugs from where, translation editor? Because by default it will not appear there.
In WordPress, you cannot disable slugs entirely for post types because slugs are a fundamental part of how WordPress handles permalinks and URL structure for posts, pages, and custom post types.
|
 panagiotisE
|
I need to have the same url in all languages for an other custom post type. For this reason in settings at Page URL I selected "Translate (this will include the slug in the translation and not create it automatically from the title)". Maybe for this reason slug appears in translation editor.
|
 Bruno Kos
WPML Supporter since 12/2018
Languages:
English (English )
German (Deutsch )
French (Français )
Timezone:
Europe/Zagreb (GMT+02:00)
|
There is no such feature (even though it is being considered), but you can consider setting that language so that it uses encoded URLs, even though it doesn't.
Because if you set "2. Copy from original language if translation language uses encoded URLs", it would copy the slugs then.
https://wpml.org/forums/topic/keep-slugs-in-english/#post-13467257
|