WordPress.org

Support

Support » Plugins and Hacks » CPT-onomies: Using Custom Post Types as Taxonomies » [Plugin: CPT-onomies: Using Custom Post Types as Taxonomies] Feature : Better integration with WPML

[Plugin: CPT-onomies: Using Custom Post Types as Taxonomies] Feature : Better integration with WPML

  • Hi,
    actually,
    when you create for each language an items and you attach your custom post type as taxomony with other post type,if your translations are same in other language it display all translations but no information to know who language using.

    for exemple :
    checkbox – item 1, name : fanless
    checkbox – item 2, name : fanless
    checkbox – item 3, name : fanless

    better if we have :
    checkbox – item 1, name : fanless (UK)
    checkbox – item 2, name : fanless (ES)
    checkbox – item 3, name : fanless (DE)

    http://wordpress.org/extend/plugins/cpt-onomies/

Viewing 11 replies - 1 through 11 (of 11 total)
  • or in your function “CPTonomy_Walker_Terms_Checklist”, display only the taxomony items with the current language.

    if we are in english translation for an items, display in all tab only related items from the current language. actually you display all items for each language in CPTonomy_Walker_Terms_Checklist.

    i used this to get the name of the translations

    function get_language_for_element_w($element_id, $el_type='post_post'){
            global $wpdb;
            return $wpdb->get_var("SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE element_id='{$element_id}' AND element_type='{$el_type}'");
        }

    Hi sireneweb,

    I had the same problem, so I added this code to my functions.php:

    function filter_cptonomies_get_terms ( $terms, $taxonomies, $args ){
    	global $sitepress;
    	$post_types = get_post_types();
    	foreach ( $terms as $iTerm => $term ){
    		if ( in_array( $term->taxonomy , $post_types ) ){
    			$post	= get_posts( 'post_per_page=1&post_type='.$term->taxonomy.'&name='.$term->slug );
    			$lang	= $sitepress->get_language_for_element($post[0]->ID, "post_{$term->taxonomy}" );
    			$term->name = "{$term->name} ({$lang})";
    		}
    	}
    	return $terms;
    }
    add_filter( 'get_terms' , 'filter_cptonomies_get_terms' , 20 , 3 );

    I would have preferred showing only the current language cpt-onomies, but when you change the language of the post (in the Language metabox), it reloads the Category taxonomy, but not the CPT-onomies taxonomies.

    I’m sure I could figure out what jQuery function gets triggered to reload the default taxonomy, but adding the language to the term name is good enough I think.

    Hey ffto!

    Great work. Thank you!
    As long as it’s not possible to show the selected language only I’ll go with your solution.

    here’s an updated version :

    function filter_cptonomies_get_terms ( $terms, $taxonomies, $args ){
    	global $sitepress;
    	$post_types = get_post_types();
    	foreach ( $terms as $iTerm => $term ){
    		if ( in_array( $term->taxonomy , $post_types ) ){
    			$post		= get_posts( 'post_per_page=1&post_type='.$term->taxonomy.'&name='.$term->slug );
    			$lang		= strtoupper( $sitepress->get_language_for_element($post[0]->ID, "post_{$term->taxonomy}" ) );
    			$current	= strtoupper( ICL_LANGUAGE_CODE );
    
    			if ( is_admin() ){
    				$term->name = "{$term->name} ({$lang})";
    			}elseif ( $lang !== $current ) {
    				unset( $terms[$iTerm] );
    			}
    		}
    	}
    	return $terms;
    }
    add_filter( 'get_terms' , 'filter_cptonomies_get_terms' , 20 , 3 );

    it shows the LANG when in the back end, but when in the front end, it shows only the ones in the current languages.

    there are a bug with your first function ffto, it doesn’t display the good langage correctly. I suspect get_language_for_element

    Hi sireneweb,

    does the second function I posted worked? I compared your function with the WPML one “get_language_for_element” and it’s exactly the same code.

    i’ve updated the function again, to validate if the user has WPML turned off, so it degrades gracefully without errors.

    function filter_cptonomies_get_terms ( $terms, $taxonomies, $args ){
    	global $sitepress;
    	if ( !isset( $sitepress ) ) return $terms;
    
    	$post_types = get_post_types();
    	foreach ( $terms as $iTerm => $term ){
    		if ( in_array( $term->taxonomy , $post_types ) ){
    			$post		= get_posts( 'suppress_filters=1&post_per_page=1&post_type='.$term->taxonomy.'&name='.$term->slug );
    			$lang		= strtoupper( $sitepress->get_language_for_element( $post[0]->ID, "post_{$term->taxonomy}" ) );
    			$current	= strtoupper( ICL_LANGUAGE_CODE );
    
    			if ( is_admin() ){
    				$term->name = "{$term->name} ({$lang})";
    			}elseif ( $lang !== $current ) {
    				unset( $terms[$iTerm] );
    			}
    		}
    	}
    	return $terms;
    }
    add_filter( 'get_terms' , 'filter_cptonomies_get_terms' , 20 , 3 );

    Do you have an example of the bug? I’m not able to reproduce the problem.

    For me, the bug comes from your request, maybe you can try to add for each language the title + lang to see if it display the sames result than your function with ({$lang})

    for exemple :
    my item 1 FR
    my item 2 EN

    check my request :
    return $wpdb->get_var("SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE element_id='{$element_id}' AND element_type='{$el_type}'");

    Then after you don’t get the sames result with your function

    function filter_cptonomies_get_terms ( $terms, $taxonomies, $args ){
    	global $sitepress;
    	$post_types = get_post_types();
    	foreach ( $terms as $iTerm => $term ){
    		if ( in_array( $term->taxonomy , $post_types ) ){
    			$post		= get_posts( 'post_per_page=1&post_type='.$term->taxonomy.'&name='.$term->slug );
    			//$lang		= strtoupper( get_language_for_element_w($term->term_id, 'post_pictos_produit') );
    			$lang		= strtoupper( $sitepress->get_language_for_element($term->term_id, "post_{$term->taxonomy}" ) );
    			$current	= strtoupper( ICL_LANGUAGE_CODE );
    
    			if ((is_admin())&&($lang == $current)){
    				$term->name = "{$term->name} ({$lang})";
    			}elseif ( $lang !== $current ) {
    				unset( $terms[$iTerm] );
    			}
    		}
    	}
    	return $terms;
    }

    i solve the bug, now we display only the terms from the current language and good terms associated from the language.

    Hi,

    This is exactly what I’d need, but unfortunately your function does not seem to work for me.

    Any ideas?

    Plugin Author Rachel Carden

    @bamadesigner

    Sorry, NTD. I, unfortunately, have no experience with WPML whatsoever although it seems like I should check it out.

    Since this post has been pretty active, I was hoping someone would help you out, and maybe they’ll speak up soon.

    When I get some free time, I’ll start to do some research on WPML. Hope you get some help soon!

    Hey Rachel,

    No worries, I’ll look into it when I have the time and post updates if I can find some resolution.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Plugin: CPT-onomies: Using Custom Post Types as Taxonomies] Feature : Better integration with WPML’ is closed to new replies.
Skip to toolbar