Created
March 28, 2018 01:03
-
-
Save rafaehlers/57b852499b11d279af254403d0d99246 to your computer and use it in GitHub Desktop.
This file contains hidden or 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