Skip to main content
added 117 characters in body
Source Link
Nicolai Grossherr
  • 18.9k
  • 8
  • 64
  • 109

get_terms returns an array of objects. You cannot echo an array, if you do, you will just get Array(). What you can do is print_r($array) or var_dump($array) or echo json_encode($array) to see the data it contains.

YouOtherwise, to get single elements, e.g. the name, from the objects, you need to pass $tax_terms through a foreach loop to get the objects from each term and then from there you can also then echo the specific object you are after

Something like this will work

$tax_terms = get_terms( $taxonomy, $args );

foreach ( $tax_terms as $tax_term ) {

    echo $tax_term->name;

}

get_terms returns an array of objects. You cannot echo an array, if you do, you will just get Array().

You need to pass $tax_terms through a foreach loop to get the objects from each term and then from there you can also then echo the specific object you are after

Something like this will work

$tax_terms = get_terms( $taxonomy, $args );

foreach ( $tax_terms as $tax_term ) {

    echo $tax_term->name;

}

get_terms returns an array of objects. You cannot echo an array, if you do, you will just get Array(). What you can do is print_r($array) or var_dump($array) or echo json_encode($array) to see the data it contains.

Otherwise, to get single elements, e.g. the name, from the objects, you need to pass $tax_terms through a foreach loop to get the objects from each term and then from there you can also then echo the specific object you are after

Something like this will work

$tax_terms = get_terms( $taxonomy, $args );

foreach ( $tax_terms as $tax_term ) {

    echo $tax_term->name;

}
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

get_terms returns an array of objects. You cannot echo an array, if you do, you will just get Array().

You need to pass $tax_terms through a foreach loop to get the objects from each term and then from there you can also then echo the specific object you are after

Something like this will work

$tax_terms = get_terms( $taxonomy, $args );

foreach ( $tax_terms as $tax_term ) {

    echo $tax_term->name;

}