Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

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
You can’t perform that action at this time.