WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 4 months ago

#43056 new defect (bug)

Notice in redirect_guess_404_permalink() when post type is an array

Reported by: junaidbhura Owned by:
Milestone: 5.0 Priority: normal
Severity: normal Version: trunk
Component: Canonical Keywords: has-patch
Focuses: Cc:

Description

When manipulating URLs, it sometimes becomes necessary to update the query using the pre_get_posts hook.

If we set the post type to an array in the pre_get_posts hook like so:

$query->set( 'post_type', array( 'post', 'page', 'my_cpt' ) );

On a 404 page, we get a notice when WP_DEBUG is set to true:

Notice: wpdb::prepare was called incorrectly. The query only expected one placeholder, but an array of multiple placeholders was sent.

This is caused by the following code in redirect_guess_404_permalink():

$where .= $wpdb->prepare(" AND post_type = %s", get_query_var('post_type'));

This can be fixed by looking for an array and updating the query.

Attachments (1)

43056.diff (853 bytes) - added by junaidbhura 5 months ago.

Download all attachments as: .zip

Change History (4)

@junaidbhura
5 months ago

#1 @junaidbhura
5 months ago

  • Keywords has-patch added

This ticket was mentioned in Slack in #core by junaidbhura. View the logs.


5 months ago

#3 @SergeyBiryukov
4 months ago

  • Milestone changed from Awaiting Review to 5.0
Note: See TracTickets for help on using tickets.