Set category instead of asking users to choose
-
Hi,
I have 3 forms, each for different categories of custom post (leaderboard_entry) – they’re scores for 3 offline puzzle box games.
Rather than have the user choose the category, i want to set the category when the CF7 is sent.
In each CF7 form i have this changing box1, box2 and box3:
[select your-category class:hidden-select value=”box1″]
Because it needs a select for taxonomies, i am just passing one value but it’s not being picked up so i’m trying to set the category after.
// Function to update the category of a post add_action('CF7_2_POST_FORM_POSTED', 'update_leaderboard_entry_category', 10, 3); function update_leaderboard_entry_category($cf7_key, $submitted_data, $submitted_files){ // Get the ID of the post that's being created by the form submission $post_id = isset($submitted_data['cf7_2_post_id']) ? intval($submitted_data['cf7_2_post_id']) : null; // Make sure we have a valid post ID if($post_id) { // Set the category of the post $term = 'box1'; // replace with your category slug $taxonomy = 'box'; // replace with your taxonomy name wp_set_object_terms($post_id, $term, $taxonomy, true); } }
Is this the way? ?? After quite a few hours on it, i’m hoping you have a better idea to achieve this!
Thanks in advance for any help you can give!
The page I need help with: [log in to see the link]
- The topic ‘Set category instead of asking users to choose’ is closed to new replies.