Want more features on Pastebin? Sign Up, it's FREE!
Guest

Query the categories in all langages with Polylang

By: Chouby on Dec 2nd, 2012  |  syntax: PHP  |  size: 0.72 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data