Set custom post default language. I created a custom post with pods and I have WPML plugin installed. I want to show this custom post only in a language which is not the default one of the website so that the urls will be http://example.com/en/postname instead of http://example.com/postname. For this I would like when i create a new post of these custom posts that their default language should be english and not the default language of the website. Otherwise I have every time to change the default language of the post for each post. How can i set another default language for the custom post than the one of the website?
Asked
Active
Viewed 682 times
1
-
Possible duplicate of [Wordpress custom post language WPML](http://stackoverflow.com/questions/26166165/wordpress-custom-post-language-wpml) – yezzz Jun 05 '16 at 19:38
-
You can change it for the specific site. http://wordpress.stackexchange.com/questions/131678/how-to-get-posts-in-different-language-from-wpml-plugin – meck373 Jun 05 '16 at 19:51
-
But i need the url to be /en/postname – user1619177 Jun 05 '16 at 20:23
2 Answers
1
add_action('save_post', 'my_english_halacha');
function my_english_halacha($post_id) {
$post_type = get_post_type($post_id);
switch( $post_type )
{
case 'english_halacha':
$set_language_args = array(
'element_id' => $post_id,
'element_type' => 'post_english_halacha',
'language_code' => 'en',
'rewrite' => array('slug' => ( (ICL_LANGUAGE_CODE=='en') ) ),
'source_language_code' => 'he',
);
global $sitepress;
$sitepress->switch_lang('en');
do_action( 'wpml_set_element_language_details', $set_language_args );
break;
case 'spanish_halacha':
$set_language_args = array(
'element_id' => $post_id,
'element_type' => 'post_spanish_halacha',
'language_code' => 'es',
'rewrite' => array('slug' => ( (ICL_LANGUAGE_CODE=='es') ) ),
'source_language_code' => 'he',
);
global $sitepress;
$sitepress->switch_lang('es');
do_action( 'wpml_set_element_language_details', $set_language_args );
break;
}
}

user1619177
- 145
- 9
0
Add the following action to functions.php, and I hope Problem will be Solved:
function update_post_language( $post_id ) {
$post_type = get_post_type($post_id);
if ($post_type == 'dwqa-question' || $post_type == 'dwqa-answer') {
$term = term_exists('ar', 'language');
if ($term !== 0 && $term !== null`enter code here`) {
wp_set_post_terms( $post_id, array ('ar'), 'language', true );
}
}
}
add_action( 'save_post', 'update_post_language' );

user1048676
- 9,756
- 26
- 83
- 120
-
I followed your code but it is not working function update_post_language( $post_id ) { $post_type = get_post_type($post_id); if ($post_type == 'english_halacha') { $term = term_exists('en', 'language'); if ($term !== 0 && $term !== null) { wp_set_post_terms( $post_id, array ('en'), 'language', true ); } } } add_action( 'save_post', 'update_post_language' ); – user1619177 Jun 06 '16 at 06:20