Kc Tan
Kc Tan

Reputation: 109

Advice on using wordpress contact form 7 hook

I have written the following codes:

// define the wpcf7_mail_sent callback 
function action_wpcf7_mail_sent( $contact_form ) { 
    $temp1246 = get_post_meta( 1246, $key = 'ID', TRUE);
    $temp1246 = intval($temp1246) + 1;
    update_post_meta( 1246, 'ID', $temp1246 );
}; 

// add the action 
add_action( 'wpcf7_mail_sent', 'action_wpcf7_mail_sent', 10, 1 ); 

What the code does is that it will increment a page's custom value by 1 every time a contact form is submitted. But the problem I have now is that I only want a specific contact form to trigger this code when it is sent, not all the contact forms (I have a few contact forms in the site powered by CF7).

May I know how can I adjust the codes above so that it is only triggered when the contact form (id = '1000') was sent for example?

Appreciate if anyone can assist, thank you!

Upvotes: 0

Views: 53

Answers (1)

Kc Tan
Kc Tan

Reputation: 109

Just found a solution that I can use the ID properties to find out which contact form I use:

if($contact_form -> id() == 1000){

}

Upvotes: 0

Related Questions