-
-
Save zackkatz/ea5127adbf519092cf2af7de0d6de318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'gravityview_entries', function( $entries, $criteria, $passed_criteria, &$total ) { | |
$view_id = GravityView_frontend::getInstance()->get_context_view_id(); | |
if ( $view_id != 97 /** Augmented View ID here */ ) { | |
return $entries; | |
} | |
$_subtract = $criteria; | |
/** Build an inverse query on isnot operations */ | |
foreach ( $_subtract['search_criteria']['field_filters'] as $key => &$filters ) { | |
if ( ! is_numeric( $key ) ) { | |
continue; | |
} | |
if ( $filters['operator'] == 'is' ) { | |
$filters = null; | |
} elseif ( $filters['operator'] == 'isnot' ) { | |
$filters['operator'] = 'is'; | |
} | |
} | |
$_subtract['search_criteria']['field_filters'] = array_filter( $_subtract['search_criteria']['field_filters'] ); | |
/** Find out the form IDs */ | |
$form_ids = array_unique( wp_list_pluck( $entries, 'form_id' ) ); | |
$subtract_entries = GFAPI::get_entries( $form_ids, $_subtract['search_criteria'], $criteria['sorting'], $criteria['paging'], $_total ); | |
$subtract_ids = wp_list_pluck( $subtract_entries, 'id' ); | |
$leftovers = array(); | |
foreach ( $entries as &$entry ) { | |
if ( in_array( $entry['id'], $subtract_ids ) ) { | |
$total--; | |
continue; | |
} | |
$leftovers[] = $entry; | |
} | |
return $leftovers; | |
}, 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment