BP_Document::get_in_operator_sql( string $field, array|bool $items )

Create SQL IN clause for filter queries.

Description

See also

Parameters

$field

(Required) The database field.

$items

(Required) The values for the IN clause, or false when none are found.

Return

(string|false)

Source

File: bp-document/classes/class-bp-document.php

1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
public static function get_in_operator_sql( $field, $items ) {
    global $wpdb;
 
    // Split items at the comma.
    if ( ! is_array( $items ) ) {
        $items = explode( ',', $items );
    }
 
    // Array of prepared integers or quoted strings.
    $items_prepared = array();
 
    // Clean up and format each item.
    foreach ( $items as $item ) {
        // Clean up the string.
        $item = trim( $item );
        // Pass everything through prepare for security and to safely quote strings.
        $items_prepared[] = ( is_numeric( $item ) ) ? $wpdb->prepare( '%d', $item ) : $wpdb->prepare( '%s', $item );
    }
 
    // Build IN operator sql syntax.
    if ( count( $items_prepared ) ) {
        return sprintf( '%s IN ( %s )', trim( $field ), implode( ',', $items_prepared ) );
    } else {
        return false;
    }
}

Changelog

Changelog
Version Description
BuddyBoss 1.4.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.