Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active April 9, 2019 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/c8af3ff2cf68414134245b31089d15a5 to your computer and use it in GitHub Desktop.
Save xnau/c8af3ff2cf68414134245b31089d15a5 to your computer and use it in GitHub Desktop.
When using Participants Database Combo Multisearch, shows how to make the selections within a multiselect field work as OR terms when global filter mode is enabled.
<?php
/**
* Plugin Name: PDB Multi Field as OR in Filter Search
* Description: make the selections within a multiselect field work as OR terms when
* global filter mode is enabled
*/
add_filter( 'pdb-multisearch_filter_mode', 'xnau_set_multi_field_as_or', 10, 2 );
/**
* sets the filter mode for the terms within a multi select field as an OR instead
* of AND when the global filter mode is enabled
*
* @param string $logic OR or AND if the global filter mode is enabled
* @param string $fieldname the current field name
* @return string must be "AND" or "OR"
*/
function xnau_set_multi_field_as_or( $logic, $fieldname )
{
/* this assumes the name of the mult-select field you want treated
* as an OR is named "interests" so change that to match your field name
*/
if ( $fieldname === 'interests' && $logic === 'AND' ) {
$logic = "OR";
}
return $logic;
}
@eldb
Copy link

eldb commented Apr 9, 2019

Selecting "OR"/"AND" could be a great extension to the "Combo Multisearch" plugin. Near the functionality of the filter from admin section "List Participants".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment