• I have the following two functions that I would like to combine into one, to where I would pass in which term(name, slug, etc) I want to get out.

    function get_rug_terms_name($term) {
        $terms = get_the_terms( get_the_ID(), $term);
        if( !empty($terms) ) {
          return implode(", ", array_map(function(WP_Term $term){
            return $term->name;
          }, $terms));
        }
      }
    
      function get_rug_terms_slug($term) {
        $terms = get_the_terms( get_the_ID(), $term);
        if( !empty($terms) ) {
          return implode(", ", array_map(function(WP_Term $term){
            return $term->slug;
          }, $terms));
        }
      }

    I was thinking something like:

    function get_rug_terms($term, $which_term)

    and then return $term->$which_term;
    but that doesn’t seem to work. Feel like i am probably close, but just not quite getting it.

    Any help would be great!!!

  • The topic ‘get_the_terms with variable’ is closed to new replies.