Title: TRYING TO GET PROPERTY ‘SLUG’ OF NON-OBJECT
Last modified: December 10, 2022

---

# TRYING TO GET PROPERTY ‘SLUG’ OF NON-OBJECT

 *  Resolved [bvedgie](https://wordpress.org/support/users/bvedgie/)
 * (@bvedgie)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/trying-to-get-property-slug-of-non-object-2/)
 * Hello all,
 * It’s probably a syntax issue, but I got this while enabling the following snippet:”
   Trying to get property ‘slug’ of non-object”.
 * It’s for hiding product cats and works fine but there is this error in logs.
   
   Can you help?
 *     ```
       add_filter( ‘get_terms’, ‘filter_get_terms’, 10, 3 );
   
       function filter_get_terms( $terms, $taxonomies, $args ) {
       $new_terms = [];
   
       // if a product category and on the shop page
   
          if ( ! is_admin() ) {
             foreach ( $terms as $term ) {
                if ( ! in_array( $term->slug, [ ‘hors-saison’, ‘non-classe’ ] ) ) {
                 $new_terms[] = $term;
                }
              }
           $terms = $new_terms;
           }
       return $terms;
       }
       ```
   
 * Thanks
    Best regards

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Anonymous User
 * (@anonymized-20801613)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/trying-to-get-property-slug-of-non-object-2/#post-16278801)
 * The [https://phpcodechecker.com/](https://phpcodechecker.com/) says No issues
   found – with your code. What does the error log says? Which PHP version are you
   using?
 *  Plugin Author [Néstor Soriano Vilchez](https://wordpress.org/support/users/konamiman/)
 * (@konamiman)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/trying-to-get-property-slug-of-non-object-2/#post-16284506)
 * Hi [@bvedgie](https://wordpress.org/support/users/bvedgie/). The error means 
   that the `$term` variable that you are processing in the loop isn’t actually 
   an instance of `WP_Term`, and thus trying to access `$term->slug` fails.
 * Without further investigation I can’t say why is this happening (you shouldn’t
   get anything but instances of `WP_Term` in that loop), but if the snippet is 
   working and all you want is to get rid of the error message, you can do so by
   modifying the condition with an extra check, so from this:
 * `if ( ! in_array(...`
 * to this:
 * `if ( ( $term instanceof WP_Term ) && ! in_array(...`
 * Please let me know if that works for you.
    -  This reply was modified 3 years, 3 months ago by [Néstor Soriano Vilchez](https://wordpress.org/support/users/konamiman/).
 *  Thread Starter [bvedgie](https://wordpress.org/support/users/bvedgie/)
 * (@bvedgie)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/trying-to-get-property-slug-of-non-object-2/#post-16286466)
 * [@konamiman](https://wordpress.org/support/users/konamiman/) Perfect!
    It seems
   to work, the error msg disappeared 🙂
 * Thanks a lot, [@konamiman](https://wordpress.org/support/users/konamiman/).
 *  Thread Starter [bvedgie](https://wordpress.org/support/users/bvedgie/)
 * (@bvedgie)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/trying-to-get-property-slug-of-non-object-2/#post-16327846)
 * Hello there,
 * I’m reopening this ticket because I just noticed that this filter was preventing
   a plugin from running ( WooCommerce Buy One Get One Free) and I don’t know how
   to do it. Do you have an idea ?
 *  [Saif](https://wordpress.org/support/users/babylon1999/)
 * (@babylon1999)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/trying-to-get-property-slug-of-non-object-2/#post-16330386)
 * Hello [@bvedgie](https://wordpress.org/support/users/bvedgie/),
 * > I’m reopening this ticket because I just noticed that this filter was preventing
   > a plugin from running ( WooCommerce Buy One Get One Free) and I don’t know 
   > how to do it. Do you have an idea ?
 * I’m afraid debugging custom solutions is not within our [scope of support](https://woocommerce.com/support-policy/)
   here in the forums.
 * I recommend you post this in the [WooCommerce Facebook group](https://www.facebook.com/groups/advanced.woocommerce/)
   or the `#developers` channel of the [WooCommerce Community Slack](https://woocommerce.com/community-slack/).
   We’re lucky to have a great community of open-source developers for WooCommerce,
   and many of our developers hang out there, as well.
   Cheers!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘TRYING TO GET PROPERTY ‘SLUG’ OF NON-OBJECT’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [slug](https://wordpress.org/support/topic-tag/slug/)

 * 5 replies
 * 4 participants
 * Last reply from: [Saif](https://wordpress.org/support/users/babylon1999/)
 * Last activity: [3 years, 3 months ago](https://wordpress.org/support/topic/trying-to-get-property-slug-of-non-object-2/#post-16330386)
 * Status: resolved