daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest May 16th, 2018 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function get_custom_terms($taxonomy)
  2. {
  3.     $args = array(
  4.       'parent' => 0,
  5.       'pad_counts' => true,
  6.       'hide_empty' => false
  7.   );
  8.  
  9.     $terms = get_terms($taxonomy, $args);
  10.  
  11.     if (count($terms) != 0) {
  12.  
  13.         foreach ($terms as $term) {
  14.  
  15.             $term = sanitize_term($term, $taxonomy);
  16.             $term_link = get_term_link($term, $taxonomy);
  17.             if (is_wp_error($term_link)) {
  18.                 continue;
  19.             }
  20.  
  21.             $array[] = $term->name;
  22.  
  23.             $term_children = get_term_children($term->term_id, $taxonomy);
  24.  
  25.             if (count($term_children) != 0) {
  26.                 foreach ($term_children as $term_id) {
  27.  
  28.                     $term_child = get_term_by('id', $term_id, $taxonomy);
  29.  
  30.                     $term_child = sanitize_term($term_child, $taxonomy);
  31.                     $term_child_link = get_term_link($term_child, $taxonomy);
  32.                     if (is_wp_error($term_child_link)) {
  33.                         continue;
  34.                     }
  35.  
  36.                     $array[]['children'] = $term_children->name;
  37.                 }
  38.             }
  39.         }
  40.         return $array;
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top