Viewing 6 replies - 16 through 21 (of 21 total)
  • Plugin Author Jupitercow

    (@jcow)

    aliferis. I will have to look at this later tomorrow. I am curious, but I have never seen the issue you are describing. I have this on my list, just no time this afternoon unfortunately.

    oh, thanks. I misunderstood – I thought that it was a similar issue to one described by burlingtonave above…

    rgds

    JOE

    its as if the plugin is not having any effect – the form is simply running in its normal ‘mode’ – allowing a front end user to add a post (which is does, elsewhere)

    Joe

    to be clear I am hoping to update the current post – my shortcode is in a single.php file but its a custom post type and a custom single template

    Joe

    I remove all other entries attached to the current form an post-id, except the newest entry.

    add_action( 'gform_after_submission_3', 'mysite_gform_after_submission_3', 10, 2 );
    
    function mysite_gform_after_submission_3 ( $entry, $form ) {
        delete_old_etries_by_post_id( $entry['post_id'], $entry['id']);
    } 
    
    function get_old_etries_by_post_id( $post_id, $entry_exclude, $form = 3 ) {
        $search_criteria = array();
        $search_criteria['field_filters'][] = array("key" => 'post_id', value => $post_id);
        $entries = GFAPI::get_entries( 3,  $search_criteria);
        return $entries;
    }
    function delete_old_etries_by_post_id( $post_id, $entry_exclude_id, $form = 3 ) {
       $entries = get_old_etries_by_post_id( $post_id, $entry_exclude_id, $form);
       foreach ($entries as &$entry) {
        GFAPI::delete_entry( $entry['id'] );
       }
    }

    Replace the 3 with the id of yout form.
    In my use case, this is better than deleting all entries.
    Althought updating the first/original entry would be better,
    anybody managed to fix this? Feel free to share your code.

    Ok, sorry, forgot the crucial part

    add_action( 'gform_after_submission_3', 'mysite_gform_after_submission_3', 10, 2 );
    
    function mysite_gform_after_submission_3 ( $entry, $form ) {
        delete_old_etries_by_post_id( $entry['post_id'], $entry['id']);
    } 
    
    function get_old_etries_by_post_id( $post_id, $entry_exclude, $form = 3 ) {
        $search_criteria = array();
        $search_criteria['field_filters'][] = array("key" => "post_id", value => $post_id);
        $search_criteria['field_filters'][] = array("key" => "id", "operator" => 'isnot', value => $entry_exclude);
        $entries = GFAPI::get_entries( $form,  $search_criteria);
        return $entries;
    }
    function delete_old_etries_by_post_id( $post_id, $entry_exclude_id, $form = 3 ) {
       $entries = get_old_etries_by_post_id( $post_id, $entry_exclude_id, $form);
       foreach ($entries as &$entry) {
        GFAPI::delete_entry( $entry['id'] );
       }
    }
Viewing 6 replies - 16 through 21 (of 21 total)
  • The topic ‘How to update w/o new entry?’ is closed to new replies.