Set custom post default language

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?

Related posts

Leave a Reply

2 comments

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