How to fix “Object of class WP_Term could not be converted to string”?

Question

I basically want to loop through each post I have and get the taxonomy/category id. After that I want to output those id’s into a single string (not as a numeric value), separated by a space.

I get this error when I try to echo the string: “Object of class WP_Term could not be converted to string”

Here is what i have so far:

  <?php
          $taxonomy = wp_get_object_terms($post->ID, 'categories');
          $ids = "";
           
          foreach ($taxonomy as $cat) {
              $ids .= $cat;
        ?>
0
09eric09 1 year 2020-07-10T17:11:01-05:00 0 Answers 65 views 0

Leave an answer

Browse
Browse