Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the plugin "Formidable" to easily manage and create forms. I have set a custom post type, and created an extra post_meta.

I can use meta('test'); within the loop to show my meta value on the posts single page.

Everytime someone creates an entry by submitting the form thats on the single post page i want the value for the meta key 'test' to be subtracted by one(updated).

The Formidable plugin comes with a action hook:

add_filter('frm_after_create_entry', 'after_entry_created', 30, 2);
function after_entry_created($entry_id, $form_id){
    if($form_id == 7){ //change 7 to the ID of your form
          //do stuff here
    }
}

I have put this in my functions.php. But how do I target the right post and right meta key?

Thanks

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

The following is a crude example, it can be improved to ensure you're dealing with integers etc and also shortened overall for brevity but this should get you started.

add_filter('frm_after_create_entry', 'after_entry_created', 30, 2);
function after_entry_created($entry_id, $form_id){

    global $post;

    if($form_id == 7){ //change 7 to the ID of your form

      $previous_value = get_post_meta($post_id, $key, true); 

      if($previous_value == null) {

        $value = 12345; //this is a starting value if nothing set
        $previous_value = $value;
        $value = $previous_value - 1; //returns 12344

      } else {

        $value = $previous_value - 1; //returns whatever previous value was - 1 

     }

      update_post_meta($post->ID, $key, $value, $previous_value);

    }
}

I'm making some assumptions without knowing if you are working with a starting value or not, but this should get you going in the right direction.

share|improve this answer
    
Thank you! I think this is the right direction. But i don't really get it to work. I need to troubleshoot where it's going wrong. How do i check what the get_post_meta returns? And yes i got a starting value. Thanks again :) –  galengodis Oct 4 '12 at 21:17
    
I got it to work, but had to remove $previous_value in update_post_meta... Anyways thnx a lot :) –  galengodis Oct 4 '12 at 21:29
    
Hum, i don't get the "get_post_meta($post_id, $key, true);" to work :/ It doesnt seem to return anything... –  galengodis Oct 4 '12 at 21:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.