<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: Add Parent post category with hook/filter</title>
		<link>https://legacy.forums.gravityhelp.com/topic/add-parent-post-category-with-hookfilter</link>
		<description>Gravity Support Forums Topic: Add Parent post category with hook/filter</description>
		<language>en-US</language>
		<pubDate>Mon, 20 Apr 2026 09:43:21 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/add-parent-post-category-with-hookfilter" rel="self" type="application/rss+xml" />

		<item>
			<title>cabaj on "Add Parent post category with hook/filter"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/add-parent-post-category-with-hookfilter#post-60350</link>
			<pubDate>Fri, 25 May 2012 03:14:03 +0000</pubDate>
			<dc:creator>cabaj</dc:creator>
			<guid isPermaLink="false">60350@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;This behavior can be achieved globally with a wordpress hook. There is no need for the 'gform_after_submission' hook.&#60;/p&#62;
&#60;p&#62;Copy this: &#60;a href=&#34;http://pastebin.com/tcvfg9L9&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/tcvfg9L9&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;If you're using default posts try hooking to the action 'save_post', 'publish_post' or 'edit_post', etc. If you're using a custom post type, instead do 'save_my-post-type', where my-post-type is your post type's slug.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>cabaj on "Add Parent post category with hook/filter"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/add-parent-post-category-with-hookfilter#post-60186</link>
			<pubDate>Thu, 24 May 2012 03:09:07 +0000</pubDate>
			<dc:creator>cabaj</dc:creator>
			<guid isPermaLink="false">60186@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I'm a PHP rookie so let me know if I'm out to lunch.  &#60;/p&#62;
&#60;p&#62;I want to do something similar to Sascha and have implemented &#60;a href=&#34;http://wordpress.org/support/topic/automatically-select-ancestor-terms-for-all-selected-terms?replies=2&#34; rel=&#34;nofollow&#34;&#62; this function &#60;/a&#62; that automatically sets the ancestor taxonomy term with the descendent is selected.&#60;/p&#62;
&#60;p&#62;It works great when publishing/editing a post from the backend - but not when a post is created with gravity forms.&#60;/p&#62;
&#60;p&#62;Any ideas on how this function can be hooked in with 'gform_after_submission'?&#60;br /&#62;
Also trying to make this work with &#60;a href=&#34;http://wordpress.org/search/front-end+editor&#34; rel=&#34;nofollow&#34;&#62;front-end editor&#60;/a&#62; but don't know how to hook it in.&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://pastebin.com/raw.php?i=P3fACKYq&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/raw.php?i=P3fACKYq&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>sascha on "Add Parent post category with hook/filter"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/add-parent-post-category-with-hookfilter#post-43031</link>
			<pubDate>Sat, 03 Dec 2011 09:59:58 +0000</pubDate>
			<dc:creator>sascha</dc:creator>
			<guid isPermaLink="false">43031@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi Dave,&#60;br /&#62;
I used the following code and it works great! Thanks for your help/pointers!!!&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;// select parent term automatically for the &#38;#39;project_type&#38;#39; taxonomy in form #1
add_action(&#38;#39;gform_after_submission_1&#38;#39;, &#38;#39;gform_parent_category&#38;#39;);
function gform_parent_category($entry) {

	$created_post = $entry[&#38;#39;post_id&#38;#39;];
	$child_ID = $entry[&#38;quot;7&#38;quot;];
	$term_object = get_term_by(&#38;#39;id&#38;#39;, $child_ID, &#38;#39;project_type&#38;#39;); // replace project_type by chosen taxonomy
	$parent_ID = $term_object -&#38;gt; parent;
	wp_set_post_terms( $created_post, $parent_ID, &#38;#39;project_type&#38;#39;, true ); //replace project_type by chosen taxonomy
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;But instead of copying the code for each form, I wanted a flexible solution: I tried to use wp_get_post_terms instead. The only problem is that function returns an empty string! No idea why?!? Quite messy code as I tried different options:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;#39;gform_after_submission&#38;#39;, &#38;#39;gform_parent_category&#38;#39;);
function gform_parent_category($entry) {

	$created_post = $entry[&#38;#39;post_id&#38;#39;];
	$post = get_post($entry[&#38;quot;post_id&#38;quot;]);
	//$child_ID = $entry[&#38;quot;7&#38;quot;];
	//$term_object = get_term_by(&#38;#39;id&#38;#39;, $child_ID, &#38;#39;project_type&#38;#39;); // replace project_type by chosen taxonomy
	$query_taxonomy = &#38;#39;project_type&#38;#39;;
	$term_object = wp_get_post_terms($created_post, $query_taxonomy, array(&#38;quot;fields&#38;quot; =&#38;gt; &#38;quot;all&#38;quot;)); // replace project_type by chosen taxonomy
	$product_terms = wp_get_object_terms($created_post, &#38;#39;project_type&#38;#39;, array(&#38;quot;fields&#38;quot; =&#38;gt; &#38;quot;all&#38;quot;));
	$parent_ID = $term_object -&#38;gt; parent;
	print_r($term_object);
	var_dump($term_object);
	var_dump($product_terms);
	var_dump($post);
	//$parent_ID = $term_object[parent];
	echo $parent_ID;
	wp_set_post_terms( $created_post, $parent_ID, &#38;#39;project_type&#38;#39;, true ); //replace project_type by chosen taxonomy
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Have you got any clues?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>David Smith on "Add Parent post category with hook/filter"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/add-parent-post-category-with-hookfilter#post-42333</link>
			<pubDate>Mon, 28 Nov 2011 17:26:53 +0000</pubDate>
			<dc:creator>David Smith</dc:creator>
			<guid isPermaLink="false">42333@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi Sascha,&#60;/p&#62;
&#60;p&#62;This is probably easiest to accomplish after the post has been created using the gform_after_submission hook as I did to do a related task in this topic: &#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://www.gravityhelp.com/forums/topic/how-to-create-a-form-that-posts-a-child-post-or-child-page&#34; rel=&#34;nofollow&#34;&#62;http://www.gravityhelp.com/forums/topic/how-to-create-a-form-that-posts-a-child-post-or-child-page&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;You will need to fetch the parent category ID by passing the selected child category (available in the $entry object) to the WP function get_category(). This function will return a category object which includes the &#34;parent&#34; property. This will be the ID of the parent category.&#60;/p&#62;
&#60;p&#62;Per my code example above, the $post_id is available in the $entry object as well.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>sascha on "Add Parent post category with hook/filter"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/add-parent-post-category-with-hookfilter#post-42276</link>
			<pubDate>Mon, 28 Nov 2011 11:19:25 +0000</pubDate>
			<dc:creator>sascha</dc:creator>
			<guid isPermaLink="false">42276@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi there,&#60;br /&#62;
I am using the &#34;post category&#34; field to populate the category of a post. This works well. What I would like to do though is:&#60;br /&#62;
if a child is chosen on the form, then the parent (or even parents) are added automatically with the help of a hook/filter. Which would be the best filter to use and how would I go about adding that parent to the post category?&#60;br /&#62;
In logic I would:&#60;br /&#62;
1. get the field value of the post category field into $child_category&#60;br /&#62;
2. use get_category_parent ($child_category) to save parent in $parent&#60;br /&#62;
3. wp_set_post_terms ($post_ID, $parent, $category, true)&#60;/p&#62;
&#60;p&#62;Do not know if that is right though. If it is the questions I have: what do I use for $post_ID and what do I use for $category?&#60;br /&#62;
As always, any help is appreciated!
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
