SHARE
TWEET

Query the categories in all langages with Polylang

Chouby Dec 2nd, 2012 83 Never
  1. /*
  2. Plugin Name: Query the categories in all langages with Polylang
  3. */
  4.  
  5. add_filter('request', 'pll_cat_request');
  6. function pll_cat_request($request) {
  7.         // default permalinks
  8.         if (isset($request['cat']))
  9.                 $cat = $request['cat'];
  10.  
  11.         // pretty permalinks
  12.         if (isset($request['category_name'])) {
  13.                 $cat = get_category_by_slug($request['category_name']);
  14.                 $cat = $cat->term_id;
  15.                 unset($request['category_name']);
  16.         }
  17.  
  18.         if (!isset($cat))
  19.                 return $request; // end here if the request is not a category
  20.  
  21.         // get the category in all languages
  22.         global $polylang;
  23.         foreach ($polylang->get_languages_list() as $lang)
  24.                 $cats[] = pll_get_term($cat, $lang);
  25.  
  26.         $request['cat'] = implode(',', $cats);
  27.         return $request;
  28. }
RAW Paste Data
Top