Support » Plugin: Ceceppa Multilingua » getting media translation by media ID

  • how can I get the media translation having the media ID?

    if I use this code in my template:

    $attachment = get_post($id_image);
    $img_alternative_text = get_post_meta($attachment->ID,'_wp_attachment_image_alt',true);

    the WP_Post object returned have always the same values for every language selected


Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Alessandro Senese


    I just added new api in my development version, you can download it here:

    To retrieve translated alt text or title you can use:

    $attachment = get_post($id_image);
    $img_alternative_text = CMLMedia::get_alternative_text( $attachment->ID );
    $img_title = CMLMedia::get_title( $attachment->ID );

    The functions are not documented yet.
    However both accept “language id/slug” as second parameter, the default one is the current language.


    thanks a lot!
    I’m using not the standard plugin because I have some others problems like menu labels, you think I can make a merge of the different versions?

    Hi again Alessandro and hi gpz_

    i just tested your dev version of the plugin and didn’t got it working sadly but i opted for a different way to get translated text from image, by simply putting the translated text in the description of the image but this cant be done for a multi language sites, hopefully i m using only english and italian now.

    So if i can help you to test it deeper it would be really cool,i used your code inside the Dynamic Featured Image (this is a wonderful plugin to get multiple featured images inside a slideshow like this tut show: loop here is the code:

    <?php if ( function_exists('dfi_get_featured_images') ) {
    		$featuredImages = dfi_get_featured_images();
    		if( !is_null($featuredImages) ){
    		  foreach($featuredImages as $images) {
    	            $caption2 = dfi_get_image_title($images['full']);
                        $caption3 = dfi_get_image_caption($images['full']);
      	            $ib = dfi_get_image_id($images['full']);
                           $caption4 = get_post_meta( $ib , '_wp_attachment_image_alt', true);
    		    }else{$caption4 = CMLMedia::get_alternative_text( $ib->ID,'it_IT' );}
    		    echo "<div class='desccont'>";
    		    echo "<p class='desc'>" . $caption2 . "</p>";
    		    echo "<p class='desc'>" . $caption3 . "</p>";
    		    echo "<p class='desc'>" . $caption4 . "</p>";
    		    echo "</div>";}
    					       } else {
    						            if ( has_post_thumbnail() ) {
    						                echo '' . the_post_thumbnail( 'full', array( 'class' => 'aligncenter' ) ) . '';
    						 } else {
    						    if ( has_post_thumbnail() ) {
    						            echo '' . the_post_thumbnail( 'full', array( 'class' => 'aligncenter' ) ) . '';

    Did i used your code correctly? And a second question:
    -A post setted to All languages will show image translated fields in the non-main language post?
    To make it easy: I have a post in All languages and my main language is english, when i m on the italian version of the site, the images in the post will show his Italian Translated Alt text?

    Plugin Author Alessandro Senese


    Hi Wenci,
    sorry for the delay.

    1) you’re using the code correctly… if doesn’t works you can try to do it yourself…
    The image fields are stored in the post meta with this key: _cml_media_meta.
    You can use this code to retrieve all the translations of the media:

    $meta = get_post_meta( $media_id, ‘_cml_media_meta’, true );

    $meta is an array containing all translated fields.

    2) depend when you have created the post. because the option to translate media fields is available only in the newest version of the plugin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘getting media translation by media ID’ is closed to new replies.