Thread Starter
WiSch
(@wisch)
Hello.
I found out, that I can use a so called Hook to realize that…
I tried the following code in my functions.php but it didn’t work.
The form ist send via Mail but the Meta-field did not change the value…
Did someone see the error?
Thanks for your help.
function wpcf7_vor_mailversand($cf7) {
$current_post_id = $post->ID;
$anmeldungen = get_post_meta($current_post_id, 'Anmeldungen', true);
$anmeldungen++;
update_post_meta($current_post_id, 'Anmeldungen', $anmeldungen);
}
add_action( 'wpcf7_before_send_mail', 'wpcf7_vor_mailversand' );
Thread Starter
WiSch
(@wisch)
Hello again.
It seems that the above code is not the problem because if I try this
function mycf7_vor_mailversand($cf7) {
$current_postid = 1952;
$anmeldungen = '33';
update_post_meta($current_postid, 'Anmeldungen', $anmeldungen);
}
add_action( 'wpcf7_before_send_mail', 'mycf7_vor_mailversand' );
it didn’t work either!?
Someone out there?
Thread Starter
WiSch
(@wisch)
Nobody can help?
Now the following code works to increment my custom field.
But as you can see, it uses a fixed Post-ID… everything I try to get the Post-ID from the actual post where the form is built in failed.
function mycf7_vor_mailversand($cf7) {
global $post;
$current_postid = 1952;
//$current_postid = $cf7->posted_data["_post_id"];
//$current_postid = $_POST['post_ID'];
//$current_postid = ($post->ID);
$anmeldungen = get_post_meta($current_postid, 'Anmeldungen', true);
$anmeldungen++;
update_post_meta($current_postid, 'Anmeldungen', $anmeldungen);
}
add_action( 'wpcf7_before_send_mail', 'mycf7_vor_mailversand' );
As you can see, I even try to pass the post-id as a field from CF7.
I also tried “global $wpdb;” or “global $_post;” instead of “global $post;” because I found somebody here in the forum that someone uses it that way…
Also tried a $anmeldungen = get_post_meta($post->ID, ‘Anmeldungen’, true); without succsess.
So at last: How can a get the Post-ID of the actual post from where the form sends?
Thanks for your help.
Thread Starter
WiSch
(@wisch)
I found a solution that works for me:
function mycf7_before_send_mail($cf7) {
// Execute this Code only for Form-ID 3!
if ( 3 == $cf7->id ) {
$my_postid = wpcf7_special_mail_tag_for_post_data( $output, ‘_post_id’ ) ;
}
}
add_action( ‘wpcf7_before_send_mail’, ‘mycf7_before_send_mail’ );
This helped me.