get_connector()->getAdapter( 'Occurrence' )->get_connection(); $connection->set_charset( $connection->dbh, 'utf8mb4', 'utf8mb4_general_ci' ); // Tables. $meta = new Meta( $connection ); $table_meta = $meta->GetTable(); // Metadata. $occurrence = new Occurrence( $connection ); $table_occ = $occurrence->GetTable(); // Occurrences. // Post id search condition. $sql = "$table_occ.id IN ( SELECT occurrence_id FROM $table_meta as meta WHERE meta.name='PostID' AND ( "; // Get the last post id. $last_id = end( $value ); foreach ( $value as $post_id ) { if ( $last_id === $post_id ) { continue; } else { $sql .= "meta.value='$post_id' OR "; } } // Add placeholder for the last post id. $sql .= "meta.value='%s' ) )"; // Check prefix. switch ( $prefix ) { case 'postid': $query->addORCondition( array( $sql => $last_id ) ); break; default: /* Translators: %s: Filter prefix. */ throw new Exception( sprintf( __( 'Unsupported filter %s.', 'mwp-al-ext' ), $prefix ) ); } } }