stream icon indicating copy to clipboard operation
stream copied to clipboard

Stream db query args not working

Open nprasath002 opened this issue 5 years ago • 2 comments
trafficstars

There is a filter in stream wp_stream_query_args to pass query arguments. However passing record__in property to the arguement does not work. Looking at the function query

		if ( ! empty( $ins ) ) {
			foreach ( $ins as $key => $value ) {
				if ( empty( $value ) || ! is_array( $value ) ) {
					continue;
				}

				$field = str_replace( array( 'record_', '__in' ), '', $key );
				$field = empty( $field ) ? 'ID' : $field;
				$type  = is_numeric( array_shift( $value ) ) ? '%d' : '%s';

				if ( ! empty( $value ) ) {
					$format = '(' . join( ',', array_fill( 0, count( $value ), $type ) ) . ')';
					$where .= $wpdb->prepare( " AND $wpdb->stream.%s IN {$format}", $field, $value ); // @codingStandardsIgnoreLine prepare okay
				}
			}
		}

Specifically line $field = str_replace( array( 'record_', '__in' ), '', $key ); For key record__in this would return __in not empty as intended.

This is true for record__not_in as well

nprasath002 avatar Jan 03 '20 05:01 nprasath002

Created a quick PR for this https://github.com/xwp/stream/pull/1045

nprasath002 avatar Jan 03 '20 06:01 nprasath002

Did you check open PRs? We've been working on it with @kasparsd for a while #977 #1011 unfortunately some missing plumbing systems (testing) have prevented this from landing.

lkraav avatar Jan 03 '20 10:01 lkraav