/ Published in: PHP
shows list of cpt for example on archive page when wpml is installed. if particular post has no translation, it shows it in default language
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // save current language $current_lang = apply_filters( 'wpml_current_language', null ); //get the default language $default_lang = apply_filters( 'wpml_default_language', null ); //fetch posts in default language do_action( 'wpml_switch_language', $default_lang); //query args 'cat' => 1 ); //build query $custom_query = new wp_query($custom_query_args); //loop while ( $custom_query->have_posts() ) : $custom_query->the_post(); //check if a translation exist $t_post_id = apply_filters( 'wpml_object_id', $post->ID, 'post', false, $current_lang ); $t_post = get_post( $t_post_id); ?> <a href="<?php echo get_permalink($t_post_id); ?>" title="<?php echo get_the_title($t_post_id); ?>"><?php echo get_the_title($t_post_id); ?></a> <?php } //no translation? display default language else{ ?> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> <?php } endwhile; wp_reset_query(); do_action( 'wpml_switch_language', $current_lang);