This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 21 replies, has 2 voices.

Last updated by Rohan Sadanandan 2 months, 3 weeks ago.

Assigned support staff: Rohan Sadanandan.

Author Posts
July 19, 2019 at 1:54 pm #4246861

sarahT-6

I am trying to build a custom loop but its displaying all languages.

July 19, 2019 at 1:58 pm #4246871

sarahT-6

Is there any documentation for custom development that doesn't include toolset?

July 19, 2019 at 2:13 pm #4246961

Rohan Sadanandan
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

Thank you for contacting WPML Support.

Could you please elaborate on your question so that I can understand it better?

For getting the current language code you can use the below-given function:

$my_current_lang = apply_filters( 'wpml_current_language', NULL );

You can refer these documentations for more information:
https://wpml.org/wpml-hook/wpml_current_language/
https://wpml.org/documentation/support/wpml-coding-api/

Thanks,
Rohan

July 19, 2019 at 2:46 pm #4247047

sarahT-6

I have actually corrected my issue but I have one more issue. If you go to this page: hidden link you will see the terms show up with term id and what not. Switch over to the french, term name and ids do not show. What could be causing this?

July 19, 2019 at 2:51 pm #4247053

sarahT-6

Here is my code:

<?php

/*
 * Template Name: Test Grid
 */


get_header(); ?>

<div class="test-container">


    <?php
    /**
    * Setup query to show the 'services' post type with '8' posts.
    * Output is title with excerpt.
    */
       $args = array(  
           'post_type' => 'resources',
           'post_status' => 'publish',
           'posts_per_page' => -1,
           'orderby' => 'date',
           'order' => 'ASC',
		   'suppress_filters' => 0
       );

       $loop = new WP_Query( $args );

?>
<?php /* working */ ?>
<select class="filters-select">
 <option value="" disabled selected> <?php _e('Publication Type','theme-text-domain'); ?></option>
 <option value="*">show all</option>
<?php
$terms = get_terms('publication_type');
 if ( !empty( $terms ) && !is_wp_error( $terms ) ){
     foreach ( $terms as $term ) {
       echo "<li>" . $term->name . "</li>";
       echo '<option value=".'.$term->slug.'">'.$term->name.'</option>';

     }
 }
	?>
</select>

<?php /* working */ 
  
// $my_current_lang = apply_filters( 'wpml_current_language', NULL );

?>
<div class="grid">
<?php

             /* echo "<pre>";
             print_r($loop);
             echo "</pre>"; */
             
while ( $loop->have_posts() ) : $loop->the_post();
       $terms = get_the_terms( $post->ID , 'publication_type' );
    ?>
       <div class="element-item <?php  echo $term->slug; ?>">
       
            <h2> <?php  echo the_title(); ?></h2>
           <p><?php  echo the_excerpt(); ?></p>
           <p>post id: <?php  the_ID(); ?></p>
           <p>Term Name: <?php echo $term->name; ?></p>
            <p>Term Id: <?php echo $term->term_id ; ?></p>
		   <p><?php  	   		
			   

			 /* foreach ( $terms as $term ) {

				echo $term->name . "<br>". $term->term_id . $term->id;

			} */

			   ?></p>
       </div> 
       <?php 

       endwhile;

       wp_reset_postdata();
    ?>

</div>

</div>

<?php get_footer(); ?>
July 19, 2019 at 3:55 pm #4247301

sarahT-6

I made some corrections to my code, see the page here:

hidden link

You will see:

Publication Type: value

Publication Type ID: value

Theme Type: value

Theme Type ID: value

Switch over to French and the publication type fields are empty. Also it duplicates those html fields too:

Publication Type:

Publication Type ID:

Publication Type:

Publication Type ID:

July 19, 2019 at 4:40 pm #4247545

Rohan Sadanandan
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

Could you please replace the line:

$terms = get_the_terms( $post->ID , 'publication_type' );

with

$pid	= $post->ID;
$pid 	= apply_filters('wpml_object_id', $pid, 'post');
$terms	= get_the_terms( $pid , 'publication_type' );

If it's still not working you can revert the code & try with a minimal installation as given below:

Can you please disable all plugins that are unrelated to WPML & Custom Post Type UI(or the plugin with which you have created the taxonomy/custom post) and switch to one of the default themes e.g. Twenty Fifteen, Do you see the same issue?

NOTE:
Also, make a backup (both files and database) for your site before updating/proceeding anything (Always a good practice!).

Thanks,
Rohan

July 19, 2019 at 5:24 pm #4247623

sarahT-6

I deactivated all the plugins and moved the custom template into 2019 theme. The errors still show.

The errors still show: hidden link

July 19, 2019 at 5:30 pm #4247689

sarahT-6

also you will notice the other custom taxonomy is working: Theme Type

July 19, 2019 at 9:16 pm #4248265

sarahT-6

The issue is coming from the custom taxonomies not showing on the translated post dashboard. Please see screenshot

July 22, 2019 at 7:43 am #4254489

Rohan Sadanandan
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

It seems that you have not translated the taxonomy into French.
Once the taxonomies are translated, this issue will be fixed.

For translating a taxonomy, navigate to All Hub Resources > Countries/Publication Type > Then edit a taxonomy > On the bottom of the page, you can see "Translate" & an "add" link next to the language. Click the link & add the translation for the taxonomy.

Also if you wish, you can just display the taxonomy as translated.
For this you need to set the taxonomies to translatable as given below:
Navigate to WPML > Settings > Taxonomies Translation
Then set "country_contact" and "contact_type" to "Translatable - use translation if available or fallback to default language"

If you have any doubts, please let me know.

Thanks,
Rohan

July 22, 2019 at 7:48 am #4254507

Rohan Sadanandan
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

You can read this documentation for more information regarding taxonomy translation:
https://wpml.org/documentation/getting-started-guide/translating-post-categories-and-custom-taxonomies/

For displaying contents as translated you can follow this documentation:
https://wpml.org/documentation/translating-your-contents/displaying-untranslated-content-on-pages-in-secondary-languages/

Thanks,
Rohan

July 22, 2019 at 4:53 pm #4260049

sarahT-6

These articles did not help, I already have these settings. Please see the screenshots.

July 22, 2019 at 4:53 pm #4260073

sarahT-6

also

July 22, 2019 at 5:06 pm #4260289

sarahT-6

image of the taxonomy translated