Skip to content

Commit 5195506

Browse files
committed
fix: enhance search query handling by improving type checks and SQL joins
1 parent 26c20bb commit 5195506

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

app/main/controllers/template/rtmedia-filters.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ function rtmedia_search_fillter_where_query( $where, $table_name ) {
751751

752752
$raw_search = wp_unslash( filter_input( INPUT_GET, 'search', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) );
753753

754-
if ( 'string' !== gettype( $raw_search ) ) {
754+
if ( ! is_string( $raw_search ) ) {
755755
$raw_search = '';
756756
}
757757

@@ -874,10 +874,11 @@ function rtmedia_search_fillter_join_query( $join, $table_name ) {
874874
$request_url = explode( '/', $request_uri );
875875
if ( ! empty( $search_by ) && 'attribute' === $search_by && ! in_array( 'attribute', $request_url, true ) ) {
876876
$join .= $wpdb->prepare(
877-
" INNER JOIN $posts_table ON ( $posts_table.ID = $table_name.media_id AND $posts_table.post_type = '$media_type' )
878-
INNER JOIN $terms_table ON ( $terms_table.slug IN (%s) )
877+
" INNER JOIN $posts_table ON ( $posts_table.ID = $table_name.media_id AND $posts_table.post_type = %s )
878+
INNER JOIN $terms_table ON ( $terms_table.slug = %s )
879879
INNER JOIN $term_taxonomy_table ON ( $term_taxonomy_table.term_id = $terms_table.term_id )
880880
INNER JOIN $term_relationships_table ON ( $term_relationships_table.term_taxonomy_id = $term_taxonomy_table.term_taxonomy_id AND $term_relationships_table.object_id = $posts_table.ID ) ",
881+
$media_type,
881882
$search
882883
); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
883884
}

0 commit comments

Comments
 (0)