Magento 2 -> Get all parent categories, all the way to the top?

Hi,

I am struggling to get the entire tree of categories for any given product.

I am only able to get either the exact category it’s in and the direct parent.

so if the product is 5 categories in, I am only ever able to get the 2 from last.

I have to note that I do not actively assign the products to all the categories along the line, just the end one.

Am I asking for the impossibles?

thanks

EDIT: I figured it out so dropping it here for anyone else that might need it:

https://www.reddit.com/user/lordofthethingybobs/comments/18m3wx9/print_all_parent_categories_of_a_given_product/?utm_source=share&utm_medium=web2x&context=3

submitted by /u/lordofthethingybobs
[link] [comments]