WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 9 months ago

#42423 new defect (bug)

Warning in redirect_guess_404_permalink if $query->post_type is an array instead of a string

Reported by: augustuswm Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8.3
Component: Canonical Keywords:
Focuses: Cc:
PR Number:

Description

I am not familiar enough with WordPress to know if this is an issue or intended.

redirect_guess_404_permalink has a block that looks like:

wp-includes/canonical.php:594

// if any of post_type, year, monthnum, or day are set, use them to refine the query
if ( get_query_var('post_type') )
  $where .= $wpdb->prepare(" AND post_type = %s", get_query_var('post_type'));
else
  $where .= " AND post_type IN ('" . implode( "', '", get_post_types( array( 'public' => true ) ) ) . "')";

This works in the case that post_type is a single value, but if it has been changed to an array of values then this looks to trigger the warning:

wp-includes/wp-db.php:1353

_doing_it_wrong( 'wpdb::prepare', __( 'The query only expected one placeholder, but an array of multiple placeholders was sent.' ), '4.9.0' );

Attachments (2)

42423.diff (816 bytes) - added by nikhiltechahead 9 months ago.
Remove warning in redirect_guess_404_permalink. It supports post_type only single-case-string but this could be array or string both.
patch-42423-b.diff (956 bytes) - added by DaveFX 9 months ago.
Improved version of patch, now passing received parameters through $wpdb->prepare

Download all attachments as: .zip

Change History (4)

#1 @DaveFX
9 months ago

I can confirm this error. According to WP_Query class, post_type could be a string or an array of strings. However, these lines only support the single-string case.

#2 @DaveFX
9 months ago

  • Summary changed from redirect_guess_404_permalink passes array of post types with single placeholder to Warning in redirect_guess_404_permalink if $query->post_type is an array instead of a string

@nikhiltechahead
9 months ago

Remove warning in redirect_guess_404_permalink. It supports post_type only single-case-string but this could be array or string both.

@DaveFX
9 months ago

Improved version of patch, now passing received parameters through $wpdb->prepare

Note: See TracTickets for help on using tickets.