Help Setting Post Categories
-
I’ve been able to map all the custom meta fields however I’m having a lot of trouble mapping the post categories and post tags. In my contact form I have a select dropdown menu (field name is “platform”) with options for existing post categories “pc” “ps4” and “xbox”.
In the Taxonomies section when I try to map Post Categories to the “platform” field it looks right but when the form is submitted the category won’t be selected. I’ve read through the documentation and even tried rolling back CF7 to version 4.7 and it still just refuses to map anything to the Post Categories taxonomy. Any help with this would be greatly appreciated!
I assume in my functions php file I’ll need to use the Default Terms Values Filter. I’ve tried to modify the filter for my purposes but so far it’s not working. My code is below:
add_filter('cf7_2_post_filter_cf7_taxonomy_terms', 'modify_my_terms',10,4); /** * Function to pre-fill form dropdown/radio/checkbox fields mapped to a taxonomy. * Hooked to 'cf7_2_post_filter_cf7_taxonomy_terms'. * @param array $terms_id initially an empty array. * @param $cf7_id the form id being loaded. * @param $field the field name for which the value is being filtered. * @param string $cf7_key unique key identifying your form. * @return array an array of term IDs to select. */ function modify_my_terms($terms_id, $cf7_id, $field, $cf7_key){ /*This filter allows you to pre-fill/select taxonomy terms fields for new submissions.*/ //assuming you have defined a checkbox field called city-locations for cf7 form 'contact-us'. if('user-submitted-address' == $cf7_key & 'platform' == $field){ $term = get_term_by('name', $field ,'category'); $terms_id = array(); $terms_id[] = $term->term_id; } return $terms_id; }The page I need help with: [log in to see the link]
The topic ‘Help Setting Post Categories’ is closed to new replies.