簡體   English   中英

設置自定義帖子默認語言

[英]Set custom post default language

設置自定義帖子默認語言。 我創建了一個帶有Pod的自定義帖子,並且安裝了WPML插件。 我只想以一種不是網站默認語言的語言來顯示此自定義帖子,以便該URL為http://example.com/en/postname而不是http://example.com/postname 為此,我想在這些自定義帖子中創建新帖子時,其默認語言應為英語,而不是網站的默認語言。 否則,我會每次都更改每個帖子的默認語言。 我如何為自定義帖子設置不同於網站的另一種默認語言?

將以下操作添加到functions.php,希望問題能夠解決:

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' );
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;
  } 

  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM