axxe16
2/5/2017 - 8:53 AM

WPML if per gestione lingue ecc

WPML if per gestione lingue ecc

<?php
//'suppress_filters' 	=> 0 permette di prendere la lingua corrente
$merchandising = get_posts(
    array(
	    'post_type'			=> 'merchandising',
	    'posts_per_page'	=> -1,
	    'suppress_filters' 	=> 0
	  )
	);

<?php 
//specifichi la stringa da tradurre e il dominio (usa lo stesso nel medesimo plugon o tema)
_e('Benefits','BST'); 

//gestione condizionale in base alla lingua corrente
if( ICL_LANGUAGE_CODE == 'it' ) {
  // Italian
} elseif( ICL_LANGUAGE_CODE == 'en' ) {
  // English
} elseif( ICL_LANGUAGE_CODE == 'fr' ) {
  // French
}

//gestione categorie tradotte 
//'taxonomy' => 'cat_lenti' evita di prenderle doppie
$custom_terms = get_terms( 'cat_lenti', array( 'taxonomy' => 'cat_lenti','hide_empty' => false ) );
<?php
//conteggia i post per lingua
function count_posts($language_code = '', $post_type = 'post', $post_status = 'publish'){

  global $sitepress, $wpdb;

  //get default language code
  $default_language_code = $sitepress->get_default_language();

  //adjust post type to format WPML uses
  switch($post_type){
    case 'page':
      $post_type = 'post_page';
      break;
    case 'post':
      $post_type = 'post_post';
      break;
  }

  //are we dealing with originals or translations?
  $slc_param = $sitepress->get_default_language() == $language_code ? "IS NULL" : "= '{$default_language_code}'";

  $query = "SELECT COUNT( {$wpdb->prefix}posts.ID )
                                FROM {$wpdb->prefix}posts
                                LEFT JOIN {$wpdb->prefix}icl_translations ON {$wpdb->prefix}posts.ID = {$wpdb->prefix}icl_translations.element_id
                                WHERE {$wpdb->prefix}icl_translations.language_code = '{$language_code}'
                                AND {$wpdb->prefix}icl_translations.source_language_code $slc_param
                                AND {$wpdb->prefix}icl_translations.element_type = '{$post_type}'
                                AND {$wpdb->prefix}posts.post_status = '$post_status'";

  return $wpdb->get_var( $query );
}
<?php
//così recupero i campi comuni
get_field( LANG_CODE . '_twitter', 'options');