# Populate hidden fields with product category and sub-category

**URL:** <https://community.gravityforms.com/t/populate-hidden-fields-with-product-category-and-sub-category/12904>\
**Category:** Get Help\
**Tags:** product, embed\_post, categories, woocommerce\
**Created:** [June 24, 2022, 9:53am UTC](https://community.gravityforms.com/t/populate-hidden-fields-with-product-category-and-sub-category/12904 "2022-06-24T09:53:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cultithrive](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/cultithrive/32/5288_2.png) [@cultithrive](https://community.gravityforms.com/u/cultithrive)\
**Post date:** [June 24, 2022, 9:53am UTC](https://community.gravityforms.com/t/populate-hidden-fields-with-product-category-and-sub-category/12904/1 "2022-06-24T09:53:13Z")

</div>

Hi All,

I need to automatically populate one hidden field with the product’s category and a second hidden field with the product’s sub-category. Is this possible and if so how?

Thank you!!

---

<div class="post-metadata">

**Author:** ![jimtrue](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/jimtrue/32/1405_2.png) [@jimtrue](https://community.gravityforms.com/u/jimtrue)\
**Post date:** [June 24, 2022, 2:57pm UTC](https://community.gravityforms.com/t/populate-hidden-fields-with-product-category-and-sub-category/12904/2 "2022-06-24T14:57:36Z")

</div>

Hi Logan,

You won’t be able to use the embed\_post merge tag to perform this action as you’ll need to programmatically pull the categories out of the post and assign them using the ‘hook’ method of Dynamically Populating a Field:

> **[Dynamically Populating a Field](https://docs.gravityforms.com/using-dynamic-population/#h-hooks)**
>
> This walk-through will give you and example of how to use each method of dynamic population to dynamically populate a field on your form!

The above article includes an example for populating the ‘post author’ and that’s the methodology you should adopt for grabbing the categories of the post.

You can use either wp\_get\_post\_categories:

> **[wp\_get\_post\_categories() | Function | WordPress Developer Resources](https://developer.wordpress.org/reference/functions/wp_get_post_categories/)**
>
> Retrieves the list of categories for a post.

or get\_the\_categories:

> **[get\_the\_category() | Function | WordPress Developer Resources](https://developer.wordpress.org/reference/functions/get_the_category/)**
>
> Retrieves post categories.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![cultithrive](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/cultithrive/32/5288_2.png) [@cultithrive](https://community.gravityforms.com/u/cultithrive)\
**Post date:** [June 27, 2022, 8:48am UTC](https://community.gravityforms.com/t/populate-hidden-fields-with-product-category-and-sub-category/12904/3 "2022-06-27T08:48:05Z")

</div>

Hi Jim,

Thank you for your reply. I will look into this.

Kind regards

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/f/fef63f0599c45e0218c30d9f5d7ca8bff9b00189.png) [@system](https://community.gravityforms.com/u/system)\
**Post date:** [July 27, 2022, 8:49am UTC](https://community.gravityforms.com/t/populate-hidden-fields-with-product-category-and-sub-category/12904/4 "2022-07-27T08:49:00Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
