Title: get_translations sorting
Last modified: March 28, 2018

---

# get_translations sorting

 *  Resolved [John Huebner](https://wordpress.org/support/users/hube2/)
 * (@hube2)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/get_translations-sorting/)
 * I looked and did not see any topics that covered this.
 * I am using `$api->get_translations($translations_args)` that I’ve found in some
   of your documentation in order to build a custom language selector that will 
   work with a custom theme.
 * All is going well, but I cannot find anything on sorting what is returned in 
   any of the documents that I’ve found.
 * Are there any parameters that I can include in `$translations_args` that will
   return the translations in a specific order or do I need to figure out how to
   order them after I get the list?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Support [dinamiko](https://wordpress.org/support/users/dinamiko/)
 * (@dinamiko)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/get_translations-sorting/#post-10152761)
 * Hi John,
 * There are not sorting paramenter in translation arguments, however you can use
   standard [PHP array functions](http://php.net/manual/en/ref.array.php) to manipulate
   the result, for example array_reverse:
 * `$items = array_reverse( mlp_custom_get_language_items() );`
 *     ```
       /**
        * Get language items.
        *
        * @return array|void
        */
       function mlp_custom_get_language_items() {
   
       	$api = apply_filters( 'mlp_language_api', NULL );
       	if ( ! is_a( $api, 'Mlp_Language_Api_Interface' ) ) {
       		return;
       	}
   
       	/**
       	 * @type int    $site_id      Base site
       	 * @type int    $content_id   post or term_taxonomy ID, *not* term ID
       	 * @type string $type         @see Mlp_Language_Api::get_request_type()
       	 * @type bool   $strict       When TRUE (default) only matching exact
       	 *                                 translations will be included
       	 * @type string $search_term  If you want to translate a search
       	 * @type string $post_type    For post type archives
       	 * @type bool   $include_base Include the base site in returned list
       	 */
       	$translations_args = array(
       		'strict'       => FALSE,
       		'include_base' => TRUE,
       	);
       	$translations      = $api->get_translations( $translations_args );
       	if ( empty( $translations ) ) {
       		return;
       	}
   
       	$items = array();
       	/** @var Mlp_Translation_Interface $translation */
       	foreach ( $translations as $site_id => $translation ) {
   
       		$url = $translation->get_remote_url();
       		if ( empty( $url ) ) {
       			continue;
       		}
   
       		$language = $translation->get_language();
       		$active   = FALSE;
       		if ( get_current_blog_id() === $site_id ) {
       			$active = TRUE;
       		}
   
       		$items[ $site_id ] = array(
       			'url'    => $url,
       			'http'   => $language->get_name( 'http' ),
       			'name'   => $language->get_name( 'native' ),
       			'active' => $active,
       		);
       	}
   
       	return $items;
       }
       ```
   
 * Thanks,
    Emili
 *  Thread Starter [John Huebner](https://wordpress.org/support/users/hube2/)
 * (@hube2)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/get_translations-sorting/#post-10161050)
 * Thanks, that’s all I needed to know. I don’t have a problem building something
   to sort the but I didn’t want to build something if it already existed.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘get_translations sorting’ is closed to new replies.

 * ![](https://ps.w.org/multilingual-press/assets/icon-256x256.png?rev=2188271)
 * [MultilingualPress](https://wordpress.org/plugins/multilingual-press/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/multilingual-press/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/multilingual-press/)
 * [Active Topics](https://wordpress.org/support/plugin/multilingual-press/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/multilingual-press/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/multilingual-press/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [John Huebner](https://wordpress.org/support/users/hube2/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/get_translations-sorting/#post-10161050)
 * Status: resolved