Skip to content

Commit 4e18584

Browse files
authored
Create gpi-gpnf-exclude-child-entries-when-attached-to-a-partial-entry.php
1 parent 4a8502b commit 4e18584

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Inventory + Nested Forms // Exclude Child Entries of Partial Entry Parents from Inventory
4+
* https://gravitywiz.com/documentation/gravity-forms-nested-forms/
5+
*
6+
* WIP: This provides very basic support for excluding child entries attached to a partial entry parent
7+
* from inventory limits.
8+
*
9+
* @todo
10+
*
11+
* 1. Apply to all child forms without needing to specify a form ID.
12+
* 2. Count child entries attached to the current partial entry.
13+
* Support has been implemented when traversing between pages; however, the Nested Forms markup AJAX request
14+
* is not aware of the current partial entry ID. Will need to pass this via the `gpnf_session_script_data`
15+
* filter so it can be accessed
16+
*/
17+
// Update "123" to your child form ID.
18+
add_filter( 'gpi_query_123', function( $query, $field ) {
19+
global $wpdb;
20+
if ( class_exists( 'GF_Partial_Entries' ) ) {
21+
if ( rgpost( 'partial_entry_id' ) ) {
22+
$meta_value_clause = $wpdb->prepare( "AND meta_value != %s", rgpost( 'partial_entry_id' ) );
23+
}
24+
$query['where'] .= "
25+
AND e.id IN (
26+
SELECT entry_id FROM {$wpdb->prefix}gf_entry_meta
27+
WHERE meta_key = 'gpnf_entry_parent'
28+
AND meta_value NOT IN(
29+
SELECT entry_id FROM {$wpdb->prefix}gf_entry_meta WHERE meta_key = 'partial_entry_id' $meta_value_clause
30+
)
31+
)";
32+
}
33+
return $query;
34+
}, 10, 2 );

0 commit comments

Comments
 (0)