Need help getting cat ID inside wpcf7_mail_components
-
I’ve been using the
wpcf7_mail_componentsfilter to modify the recipient of a form dynamically. It’s based on a custom field set for the post or page where the form is sent from. I’m extracting the post ID withwpcf7_special_mail_tag(). This works well if the form is used on any post or page, but it fails when used on a category page. I have the custom field set up for both pages / posts and categories, and I need the form to work on both.My question: how do I find the ID of the category page that the form is sent from?
Code:
function set_question_form_recipient($components, $form, $object) { if ($form->id() == 102) : // Get the post ID $post_id = wpcf7_special_mail_tag('', '_post_id'); // Get the recipient e-mail address from an Advanced Custom Field $recipient_email = get_field( 'name_of_acf_field', $post_id ); // Here I need a solution for finding the category page ID, if the form was sent from a category page. From there I can find the category custom field to set the recipient. if ($recipient_email) : // Set the recipient $components['recipient'] = $recipient_email; endif; endif; // Return the modified array return $components; } add_filter('wpcf7_mail_components', 'set_question_form_recipient', 10, 3);
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Need help getting cat ID inside wpcf7_mail_components’ is closed to new replies.