PHP Warning: Attempting to read property

I am getting some warnings in this block of code.

The warnings are “Attempt to read property “id” on bool”, “Attempt to read property “id” on array” and “Attempt to read property “id” on string”. They are all for the array_push line.

   // Get the taxonomy's terms
    $terms = get_terms(
        array(
            'taxonomy'   => 'product_cat',
            'hide_empty' => false,
        )
    );

    // Get all adminboxes
    if ( !empty( $terms ) && is_array( $terms ) ) {
       $allRutor = []; 
        foreach( wp_get_post_terms( get_the_id(), 'product_cat' ) as $term ) {
            $fields = get_fields($term);
            
            if( $fields ) {
                foreach((array) $fields as $name => $value ) {
                    array_push($allRutor, $value->ID);
                }
            }
        }
        // Get unique adminboxes
        $unikRutor = array_filter(array_unique($allRutor, SORT_REGULAR), 'strlen');
    }

Leave a Comment