<?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: Posting Using Category Slug</title>
		<link>https://legacy.forums.gravityhelp.com/topic/posting-using-category-slug</link>
		<description>Gravity Support Forums Topic: Posting Using Category Slug</description>
		<language>en-US</language>
		<pubDate>Sat, 04 Apr 2026 03:02:41 +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/posting-using-category-slug" rel="self" type="application/rss+xml" />

		<item>
			<title>David Smith on "Posting Using Category Slug"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/posting-using-category-slug#post-50114</link>
			<pubDate>Tue, 21 Feb 2012 12:52:20 +0000</pubDate>
			<dc:creator>David Smith</dc:creator>
			<guid isPermaLink="false">50114@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Try using print_r() to echo out the $categories variable to see if you're successfully retrieving any categories. If so, check and make sure the slug property exists for these categories.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Noel Green on "Posting Using Category Slug"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/posting-using-category-slug#post-50032</link>
			<pubDate>Mon, 20 Feb 2012 18:11:12 +0000</pubDate>
			<dc:creator>Noel Green</dc:creator>
			<guid isPermaLink="false">50032@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I had tried that... &#60;/p&#62;
&#60;p&#62;Is it because all of the categories are in custom taxonomies?&#60;br /&#62;
I'm betting yes.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>David Smith on "Posting Using Category Slug"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/posting-using-category-slug#post-50019</link>
			<pubDate>Mon, 20 Feb 2012 16:24:55 +0000</pubDate>
			<dc:creator>David Smith</dc:creator>
			<guid isPermaLink="false">50019@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi Noel,&#60;/p&#62;
&#60;p&#62;It doesn't look like it'd take much to convert this to slugs rather than IDs. This bit from the &#60;strong&#62;get_greenmy_home_ids()&#60;/strong&#62; function would need to be updated like so:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;[php]
foreach($categories as $category)
    $cat_ids[] = $category-&#38;gt;slug;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;You might consider renaming the variables through out to indicate that you are using slugs now (ie $cat_ids would be come $cat_slugs).&#60;/p&#62;
&#60;p&#62;You would also want to make sure you update the values of your custom category field in GF to use the slugs as well.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Noel Green on "Posting Using Category Slug"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/posting-using-category-slug#post-50002</link>
			<pubDate>Mon, 20 Feb 2012 14:39:09 +0000</pubDate>
			<dc:creator>Noel Green</dc:creator>
			<guid isPermaLink="false">50002@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I'm using this code below to post into specific categories using the category ID… and it works great… what I'm wondering is if there's a way to make it grab and use the category &#34;slug&#34; instead?&#60;/p&#62;
&#60;p&#62;I have, literally, over 1,000 categories.  And when I make a new one (or a new set of them) referencing the category ID takes forever.  If I could simply type in the slug it would make life oh-so-easy!&#60;/p&#62;
&#60;p&#62;Here's the code...&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;/* Gravity Forms Posting */

add_action(&#38;#39;gform_post_submission&#38;#39;, &#38;#39;gform_add_greenmy_home&#38;#39;, 10, 2);
function gform_add_greenmy_home($entry, $form){

    if(!rgar($entry, &#38;#39;post_id&#38;#39;))
        return;

    $post_id = rgar($entry, &#38;#39;post_id&#38;#39;);
    $valid_cat_ids = get_greenmy_home_ids();
    $cat_ids = array();

    foreach($form[&#38;#39;fields&#38;#39;] as $field){

        if(strpos($field[&#38;#39;cssClass&#38;#39;], &#38;#39;add_greenmy_home&#38;#39;) === false)
            continue;

        foreach($entry as $key =&#38;gt; $value){

            if(intval($key) != $field[&#38;#39;id&#38;#39;] &#124;&#124; !in_array($value, $valid_cat_ids))
                continue;

            $cat_ids[] = (int) $value;

        }

    }

    wp_set_object_terms($post_id, $cat_ids, &#38;#39;greenmy_home&#38;#39;, false);

}

function get_greenmy_home_ids(){

    $categories = get_terms(&#38;#39;greenmy_home&#38;#39;, &#38;#39;hide_empty=0&#38;#39;);
    $cat_ids = array();

    foreach($categories as $category)
        $cat_ids[] = $category-&#38;gt;term_id;

    return $cat_ids;
}

function print_greenmy_home($array){
    echo &#38;#39;&#38;lt;pre&#38;gt;&#38;#39;;
    print_r($array);
    echo &#38;#39;&#38;lt;/pre&#38;gt;&#38;#39;;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>
