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 "slug" instead?
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!
Here's the code...
/* Gravity Forms Posting */
add_action('gform_post_submission', 'gform_add_greenmy_home', 10, 2);
function gform_add_greenmy_home($entry, $form){
if(!rgar($entry, 'post_id'))
return;
$post_id = rgar($entry, 'post_id');
$valid_cat_ids = get_greenmy_home_ids();
$cat_ids = array();
foreach($form['fields'] as $field){
if(strpos($field['cssClass'], 'add_greenmy_home') === false)
continue;
foreach($entry as $key => $value){
if(intval($key) != $field['id'] || !in_array($value, $valid_cat_ids))
continue;
$cat_ids[] = (int) $value;
}
}
wp_set_object_terms($post_id, $cat_ids, 'greenmy_home', false);
}
function get_greenmy_home_ids(){
$categories = get_terms('greenmy_home', 'hide_empty=0');
$cat_ids = array();
foreach($categories as $category)
$cat_ids[] = $category->term_id;
return $cat_ids;
}
function print_greenmy_home($array){
echo '<pre>';
print_r($array);
echo '</pre>';
}