gwp_parent_slug
The gwp_parent_slug Merge Tag for Gravity Forms returns the slug of one of the parent posts of the current post and let’s you pick the depth of ancestor you need. It only returns a value if there is actually a parent post.
Slug of the direct parent post
{gwp_parent_slug}
Returns the slug of the direct parent post (first ancestor) of the current page. Default is depth=0, which return the direct parent. depth=’top’ returns the highest parent.
Example
Let’s say we have a post called ‘Me’. The parent of this post is ‘Mama’ (slug = mama). The parent of the post ‘Mama’ is ‘Grandma’ (slug = grandma) en the parent post of Grandma is ‘Great Grandma’ (slug = great-grandma).

So when we are reading the ‘Me’ article, the url looks like this:
https://gravitywp.com/great-grandma/grandma/mama/me/
Merge Tag | Output | Information |
---|---|---|
{gwp_parent_slug} or{gwp_parent_slug depth="0"} | mama | If you want the get the direct parent of the current post. |
{gwp_parent_slug depth="1"} | grandma | Get’s you the parent of your parent. |
{gwp_parent_slug depth="2"} | great-grandma | Get’s you the parent of the parent of your parent. |
{gwp_parent_slug depth="top"} | great-grandma | Get’s you the ‘oldest’ or better said ‘highest’ parent |
Or you can see it like this:
|
|
| |
great-grandma/ | grandma/ | mama/ | me/ |
| {gwp_parent_slug} |
What’s the difference with gwp_url?
The gwp_url will look at the full url and use that as basis for indexing which part of the url you want. So it doesn’t check if there is a parent post, it will just give you any part of the slug (also if that is a category page for example).
The gwp_parent_slug will look if there is actually a parent post (parent page) and give you the slug of this parent (or higher parent if you use the depth parameter).
This is very handy if you’re using the parent post slugs in your gvlogic shortcode of Gravity Forms conditional logic shortcode, since you can for example only show certain information if the page is a child of a certain parent.
For example:
[gvlogic if="{gwp_parent_slug}" is="mama"]Show this content when my current parent post slug is mama.[/gvlogic]
[gravityforms action="conditional" merge_tag="{gwp_parent_slug depth='top'}" condition="is" value="great-grandma"]Show this content when the highest parent post slug is great-grandma.[/gravityforms]
Last updated: 06-12-2024