Prevent Exporting Orphaned Entries with GravityExport

Prevents exporting orphaned entries when using GravityExport with Nested Forms. Applies to all forms by default.

Instructions

Code

Filename: gpnf-prevent-exporting-orphaned-entries-with-gravityexport.php

<?php
/**
 * Gravity Perks // Nested Forms // Prevent Exporting Orphaned Entries with GravityExport
 * https://gravitywiz.com/documentation/gravity-forms-nested-forms/
 *
 * Prevents exporting orphaned entries when using GravityExport with Nested Forms. Applies to all forms by default.
 *
 * Instructions
 *
 * 1. Install the snippet.
 *    https://gravitywiz.com/documentation/managing-snippets/#where-do-i-put-snippets
 *
 * 2. Profit.
 */
add_filter( 'gfexcel_output_rows', function( $rows ) {
	for ( $i = count( $rows ) - 1; $i >= 0; $i-- ) {
		foreach ( $rows[ $i ] as $row_value ) {
			if ( $row_value && $row_value->getField()->id == 'gpnf_entry_parent' && $row_value->getValue() && ! is_numeric( $row_value->getValue() ) ) {
				unset( $rows[ $i ] );
			}
		}
	}
	return $rows;
} );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.